我正在更新 Retrofit 以使用 Retrofit2 并且我已经设法完成了很多事情 GET、POST、PUT...
但是我有一个请求,我必须发送一个完整的 JSON 我设法在 Retrofit 1.9 中做到了,但在 Retrofit2 中不支持它。
import retrofit.mime.TypedString;
public class TypedJsonString extends TypedString {
public TypedJsonString(String body) {
super(body);
}
@Override
public String mimeType() {
return "application/json";
}
}
如何制作retrofit2?
最佳答案
您可以从字面上强制 header 为 application/json
(正如您所做的那样)并将其作为字符串发送...
..
Call call = myService.postSomething(
RequestBody.create(MediaType.parse("application/json"), jsonObject.toString()));
call.enqueue(...)
然后..
interface MyService {
@GET("/someEndpoint/")
Call<ResponseBody> postSomething(@Body RequestBody params);
}
还是我在这里遗漏了什么?
关于java - Retrofit2 将正文作为 Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35353205/