自定义HTTP方法在Retrofit 2中不起作用

Che*_*ani 2 java android retrofit2 okhttp3

您好,我在代码中使用了自定义方法,如下所示,但它始终为我提供帮助

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); 
Run Code Online (Sandbox Code Playgroud)

我正在使用以下依赖项。

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'
Run Code Online (Sandbox Code Playgroud)

你能帮我么。

Mas*_*rzi 6

我遇到了同样的问题,在搜索文档后,我发现问题是retrofit版本,请尝试使用版本2.4.0或更高版本。

implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
Run Code Online (Sandbox Code Playgroud)