当前位置 : 主页 > 手机开发 > android >

使用Android Annotation REST服务的POST请求

来源:互联网 收集:自由互联 发布时间:2021-06-11
我在我的项目中使用 Android Annotation并尝试通过以下代码发送POST请求,但是下面的代码有问题,因为我没有按预期得到响应: @Rest(rootUrl = "http://xyz.com", converters = {GsonHttpMessageConverter.class}
我在我的项目中使用 Android Annotation并尝试通过以下代码发送POST请求,但是下面的代码有问题,因为我没有按预期得到响应:

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

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

数据是(键,值)对.是否有我遗漏的任何东西我是否必须设置请求标头或数据不应该是JSON?

我从 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);
网友评论