2

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.

Yupi
  • 4,402
  • 3
  • 18
  • 37
Chetak Bhimani
  • 459
  • 4
  • 19
  • so remove the `@Body RequestBody password`. what is the request method that you are supposed to do? GET?POST?PUT? – matrix Jan 31 '18 at 10:11
  • I need to pass the password in a body as raw data: {"password":"*****"}. Also I am using custom http mehod as given in: https://github.com/square/retrofit/blob/07d1f3de5e0eb11fb537464bd14fdbacfc9e55a7/retrofit/src/test/java/retrofit/RequestBuilderTest.java#L52-L64 – Chetak Bhimani Jan 31 '18 at 10:15
  • what is the uri that you have to send the request? is it auth/login/{deviceId} ? what method do you have to execute? – matrix Jan 31 '18 at 10:17
  • No, URL is: http://serverurl/login/{deviceId} and AUTH is Custom method name – Chetak Bhimani Jan 31 '18 at 10:21
  • why are you making up http methods? Read https://softwareengineering.stackexchange.com/questions/193821/are-there-any-problems-with-implementing-custom-http-methods tldr don't use custom methods – Tim Jan 31 '18 at 10:31
  • it is the requirement to use custom AUTH method to call API, Backend developer put such restrictions. – Chetak Bhimani Jan 31 '18 at 13:08

1 Answers1

6

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'
Masoud Darzi
  • 640
  • 9
  • 16