Question

I am using Android Annotation in my project and trying to send POST request through following code, however there is something wrong in following code as I am not getting response as expected:

@Rest(rootUrl = "http://xyz.com", converters = {GsonHttpMessageConverter.class})
public interface A {

    @Post("/authenticate/email/")
    public Object attemptLogin(Map data);
}

Where data is (key, value) pair. Is there anything I am missing perhaps Do I have to set request-header or data should not be JSON?

Était-ce utile?

La solution

I found the solution from Rest client using Android-Annotations.

Like the GET requests, it is extremely simple to send POST requests using Android-Annotations. One difference is that you need to define the parameters that you are going to send as a custom class (e.g. Event class in the example below) or if you want to control this dynamically, then a Map (e.g. a MultiValueMap). The url for the request can still be constructed in a similar fashion using the variables enclosed inside {...} and the response can be handled similarly as in GET requests.

@Post("/events")
void addEvent(Event event);

@Post("/events/{id}")
void addEventById(Event event, long id);

@Post("/authenticate/event/")
Object authenticateEventData(MultiValueMap data);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top