簡體   English   中英

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

[英]Custom HTTP method not working in Retrofit 2

你好,我在我的代碼中使用了自定義方法,如下所示,但它總是給我

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'

你能幫我嗎。

我遇到了同樣的問題,在搜索文檔后,我發現問題出在retrofit版本上,嘗試使用2.4.0或更高版本。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM