与Android注释REST服务POST请求 [英] POST request with Android Annotation REST Service
问题描述
我使用的Android注释在我的项目,并尝试发送 POST
通过以下code的请求,但没有在以下code作为我没有得到预期的反应有些不对劲:
@Rest(使用rootUrl =http://xyz.com,转换器= {} GsonHttpMessageConverter.class)
公共接口A { @Post(/身份验证/电子邮件/)
公共对象attemptLogin(地图数据);
}
其中,数据
是(键,值)
对。有什么我很想念也许我必须设置请求头
或数据
不应该是JSON?
我发现从的 REST客户端使用Android的注解。
的GET请求一样,它是非常简单的发送采用Android的注解POST请求。一个区别是,你需要定义你要发送一个自定义类(例如事件类在下面的例子),或者如果你想动态控制这个参数,然后一个Map(如MultiValueMap)。该请求的URL仍然可以在使用封闭的内部{...}变量和响应类似的方式来构造,可以类似地处理如在GET请求
块引用>@Post(/事件)
无效的addEvent(事件事件);@Post(/事件/(编号))
无效addEventById(事件事件,长ID);@Post(/身份验证/事件/)
对象authenticateEventData(MultiValueMap数据);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 setrequest-header
ordata
should not be JSON?解决方案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);
这篇关于与Android注释REST服务POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!