自定义HTTP方法在Retrofit 2中不起作用 [英] Custom HTTP method not working in Retrofit 2
本文介绍了自定义HTTP方法在Retrofit 2中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我在我的代码中使用了自定义方法,如下所示,但它总是给我
Hello I have used custom method in my code as below but it always gives me
java.lang.IllegalArgumentException:方法AUTH必须没有
请求正文。
java.lang.IllegalArgumentException: method AUTH must not have a request body.
我的代码无法正常工作总是说:自定义方法AUTH,必须没有Body
My code is not working it always says: 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'
你能帮我吗。
推荐答案
我有同样的问题,在搜索并深入研究文档后,我认为问题是改造
版本,尝试使用版本 2.4.0
。
I had the same issue and after searching and digging into the documentation, I fount that the problem was retrofit
version , try using version 2.4.0
.
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
这篇关于自定义HTTP方法在Retrofit 2中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文