Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit: 500 internal server error

I have 500 internal server error, every time when i try to send POST request via Retrofit. When i sending GET request, it sending correctly. I'm sure that with serverside everyting is ok. What's wrong with my code ?

    String ENDPOINT = "http://52.88.40.210";
    //model for request
        FriendModel ff = new FriendModel();
        ff.setFriendNumber("380935275259");
        ff.setId(516);
        ff.setNumber("380936831127");

        RestAdapter adapter = new RestAdapter.Builder()
                .setEndpoint(ENDPOINT)
                .build();
        WayfAPI api = adapter.create(WayfAPI.class);
        api.getFriendsLocation(ff, new Callback<List<FriendLocationModel>>() {
            @Override
            public void success(List<FriendLocationModel> friendLocationModels, Response response) {
                for (FriendLocationModel ff : friendLocationModels) {
                    Log.d("myLogs", "===========Successful==========");
                    Log.d("myLogs", "Id: " + ff.getId());
                    Log.d("myLogs", "Number: " + ff.getNumber());
                    Log.d("myLogs", "GeoLocation: : " + ff.getGeoLocation());
                }
            }

            @Override
            public void failure(RetrofitError error) {
                Log.d("myLogs", "-------ERROR-------");
                Log.d("myLogs", Log.getStackTraceString(error));
            }
        });
    }

Declaration of request:

@Headers({
        "Accept: application/json",
        "Content-type: application/json"
})
@POST("/api/geo/getLoc")
public void getFriendsLocation(@Body FriendModel friendModel, Callback<List<FriendLocationModel>> response);

Exampe of request and response from Postman: enter image description here

like image 686
kkost Avatar asked Sep 28 '15 10:09

kkost


People also ask

What is 500 server internal error?

The HyperText Transfer Protocol (HTTP) 500 Internal Server Error server error response code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.

How do I fix 500 internal server error IIS?

IIS error The error 500.19 is an internal server error often occurring on a server using Microsoft IIS software. It indicates that the configuration data for the page is invalid. To solve the issue, delete the malformed XML element from the Web. config file or from the ApplicationHost.


1 Answers

It seems that in postman you're sending an array of FriendModel, but in your code you're sending a single object.

Just change the object you're sending, and instead of sending a single object, send a List as the server expects

    List<FriendModel> friendsList = new ArrayList<FriendModel>();

    FriendModel ff = new FriendModel();
    ff.setFriendNumber("380935275259");
    ff.setId(516);
    ff.setNumber("380936831127");

    friendsList.add(ff);

You should also change this signature:

public void getFriendsLocation(@Body FriendModel friendModel, Callback<List<FriendLocationModel>> response);

to

public void getFriendsLocation(@Body List<FriendModel> friendModel, Callback<List<FriendLocationModel>> response);
like image 77
Udi Idan Avatar answered Oct 03 '22 16:10

Udi Idan