Retrofit 在发送之前在哪里构建完整的 JSON?
Where in Retrofit build the full JSON before sending it?
我正在使用改造和 get Bad Request ,我想知道这个库中是否有一个地方可以在发送之前以字符串格式构建完整的 JSON。
new String(((TypedByteArray) request.getBody()).getBytes());
如果要在运行时检查 JSON 以进行调试,您可以在 RestAdapter.Builder
上调用 setLogLevel(LogLevel.FULL)
。
FULL
logs the headers, body and metadata for both requests and responses 到 logcat.
为了构建一个 JSON 格式的正文,创建一个具有 class 的对象,其属性与您要发送到服务器的属性相同。使用 RestAdapter 设置的 GSON 库(或您正在使用的任何库)应该以 JSON 格式发送带有正文的请求。
还要确保调用被@POST注解并且参数被@Body注解 下面是一个例子:
@POST("/login")
User login(@Body LoginUser loginUser);
我正在使用改造和 get Bad Request ,我想知道这个库中是否有一个地方可以在发送之前以字符串格式构建完整的 JSON。
new String(((TypedByteArray) request.getBody()).getBytes());
如果要在运行时检查 JSON 以进行调试,您可以在 RestAdapter.Builder
上调用 setLogLevel(LogLevel.FULL)
。
FULL
logs the headers, body and metadata for both requests and responses 到 logcat.
为了构建一个 JSON 格式的正文,创建一个具有 class 的对象,其属性与您要发送到服务器的属性相同。使用 RestAdapter 设置的 GSON 库(或您正在使用的任何库)应该以 JSON 格式发送带有正文的请求。
还要确保调用被@POST注解并且参数被@Body注解 下面是一个例子:
@POST("/login")
User login(@Body LoginUser loginUser);