简体   繁体   中英

Getting RetrofitError: 500 Internal Server Error

Im checking how RetroFit works and tried the following:

RestClient:

public class RestClient {

    private static TaskService REST_CLIENT;
    private static String ROOT =
            "URL";
    static {
        setupRestClient();
    }

    private RestClient() {}

    public static TaskService get() {
        return REST_CLIENT;
    }

    private static void setupRestClient() {
        OkHttpClient OkHttpClient=new OkHttpClient();

        RestAdapter.Builder builder = new RestAdapter.Builder()
                .setEndpoint(ROOT)
                .setClient(new OkClient(new OkHttpClient()))
        .setConverter(new SimpleXmlConverter());
        builder.setLogLevel(RestAdapter.LogLevel.FULL);
        RestAdapter restAdapter = builder.build();
        REST_CLIENT = restAdapter.create(TaskService.class);
    }
}

In Activity:

public void testMethod()
    {
        User user=new User("58","345435","4","","0");
        RestClient.get().getWeather(user,new Callback<String>() {

            @Override
            public void success(String s, Response response) {
                Log.d("testret", "success: " + s);
                Log.d("testret", "successu: " + response.getUrl());
                Log.d("testret", "successs: " + response.getStatus());
            }
            @Override
            public void failure(RetrofitError error)
            {
                Log.d("testret", "errore: " + error);
                Log.d("testret", "erroru: " + error.getUrl());
            }
        });
    }

User:

public class User {



    String FTID,UUID,TYPE,DateTimeStamp,SDFVersionNb;

    public User(String FTID,String UUID,String TYPE,String DateTimeStamp,String SDFVersionNb)
    {
        this.DateTimeStamp=DateTimeStamp;
        this.FTID=FTID;
        this.UUID=UUID;
        this.SDFVersionNb=SDFVersionNb;
        this.TYPE=TYPE;
    }
}

Interface:

public interface TaskService {

    @POST("/GetBulkQueryUpdates")
    void getWeather(@Body User user,
                    Callback<String> callback);
}

the above webservice method returns the follwing:

<ROWS>
<ROW>
<GroupBy>3</GroupBy>
<QUERY>
 Query Statement
</QUERY>
</ROW>
</ROWS>

So i am using the post method to retrieve the above data, but i keep on getting an internal server error 500 each time though when executing the webservice method from the web, data is being retrieved. so the problem is with the code above but i cant figure out what. i tried adding the .setConverter(new SimpleXmlConverter()); after looking at the following URL: Android Retrofit return status 500 internal server error but it was the same.

any help would be appreciated.

Try this..... Adding a .xml will fix the problem

public interface TaskService {

@POST("/GetBulkQueryUpdates.xml")
void getWeather(@Body User user,
                Callback<String> callback);
}

And ur User class has to be in this format

@Root(name = "breakfast_menu")
public class BreakFastMenu
{
@ElementList(inline = true)
List<Food> foodList;
}

@Root(name="food")
public class Food
{
@Element(name = "name")
String name;

@Element(name = "price")
String price;

@Element(name = "description")
String description;

@Element(name = "calories")
String calories;
}

EDIT 1:

@Root is a annotation and in ur case it should be @Root(name = "ROWS") which is the root element of ur XML

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM