gpt4 book ai didi

android - 使用 Android Annotation REST 服务的 POST 请求

转载 作者:太空宇宙 更新时间:2023-11-03 12:21:44 24 4
gpt4 key购买 nike

我正在使用 Android Annotation在我的项目中并尝试通过以下代码发送 POST 请求,但是以下代码有问题,因为我没有收到预期的响应:

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

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

其中 data(key, value) 对。有什么我遗漏的吗?我必须设置 request-header 还是 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);

关于android - 使用 Android Annotation REST 服务的 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13905047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com