小编adi*_*nes的帖子

POST主体JSON使用Retrofit

我正在尝试使用Retrofit库POST一个JSONObject,但是当我在接收端看到请求时,内容长度为0.

在RestService接口中:

@Headers({
        "Content-type: application/json"
})
@POST("/api/v1/user/controller")
void registerController( 
     @Body JSONObject registrationBundle, 
     @Header("x-company-device-token") String companyDeviceToken, 
     @Header("x-company-device-guid") String companyDeviceGuid, 
     Callback<JSONObject> cb);
Run Code Online (Sandbox Code Playgroud)

它被调用,

mRestService.registerController(
    registrationBundle, 
    mApplication.mSession.getCredentials().getDeviceToken(), 
    mApplication.mSession.getCredentials().getDeviceGuid(),
    new Callback<JSONObject>() {
        // ...
    }
)
Run Code Online (Sandbox Code Playgroud)

我确定registrationBundle,这是一个JSONObject非空或空(其他字段肯定是好的).在提出请求时,它将注销为: {"zip":19312,"useAccountZip":false,"controllerName":"mine","registrationCode":"GLD94Q"}.

在请求的接收端,我看到请求已经Content-type: application/json有了Content-length: 0.

是否有任何理由为什么在这样的身体中发送JSON不起作用?我在使用Retrofit时遗漏了一些简单的东西吗?

rest post android json retrofit

10
推荐指数
1
解决办法
3万
查看次数

标签 统计

android ×1

json ×1

post ×1

rest ×1

retrofit ×1