Custom HTTP method not working in Retrofit 2

空扰寡人 提交于 2019-12-06 10:49:06

问题


Hello I have used custom method in my code as below but it always gives me

java.lang.IllegalArgumentException: method AUTH must not have a request 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); 

I am using below dependancies.

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'

Can you please help me.


回答1:


I had the same issue and after searching into the documentation, I found that the problem was retrofit version, try using version 2.4.0 or higher.

implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'


来源:https://stackoverflow.com/questions/48539478/custom-http-method-not-working-in-retrofit-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!