【发布时间】:2018-07-10 09:42:26
【问题描述】:
您好,我在我的代码中使用了自定义方法,如下所示,但它总是给我
java.lang.IllegalArgumentException:方法 AUTH 不能有 请求正文。
我的代码不工作它总是说:Custom method AUTH, must not have a Body
@Headers("Content-Type: application/json")
@HTTP(method = "AUTH", path = "login/{deviceId}", hasBody = true)
Call<Success> getLogin( @Path("deviceId") int deviceId, @Body RequestBody password);
我正在使用以下依赖项。
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
你能帮帮我吗?
【问题讨论】:
-
所以删除
@Body RequestBody password。你应该做的请求方法是什么? GET?POST?PUT? -
我需要将密码作为原始数据传递给正文:{"password":"*****"}。我也在使用自定义 http 方法,如:github.com/square/retrofit/blob/…
-
发送请求的 uri 是什么?是 auth/login/{deviceId} 吗?你必须执行什么方法?
-
不,URL 是:serverurl/login{deviceId} 并且 AUTH 是自定义方法名称
-
你为什么要编造http方法?阅读softwareengineering.stackexchange.com/questions/193821/…tldr 不要使用自定义方法
标签: java android retrofit2 okhttp3