RetroFit 2 Malforms URL when using PUT

Viewed 1075

I have a retrofit 2 api. My interface is as follows:

public interface Api {

    ...

    @Headers({"Content-Type: application/json"})
    @POST("/api/Login")
    Call<User> login(@Body LoginRequest loginRequest);

    @Headers({"Content-Type: application/json"})
    @PUT("/api/User/{id}")
    Call<User> updateDetails(@Path("id") String parentId, @Header("Cookie") String session, @Body UpdateProfileRequest profileDataRequest);
}

I create my Webservice instance as follows:

private static final Retrofit getAdapter() {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient httpClient = new OkHttpClient();
    httpClient.interceptors().add(logging);

    String url = String.format("http://%s:%s", BuildConfig.SERVER, BuildConfig.PORT);
    return new Retrofit.Builder()
            .baseUrl(url)
            .client(httpClient)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}

Now when I call LOGIN (a GET) or REGISTER (a POST), it works fine. But when I make a call to the PUT method it malforms the URL:

Response{protocol=http/1.1, code=404, message=Not Found, url=http://.../Account/Unauthorized/?ReturnUrl=%2Fapi%2FUser%2F9e5851bc-3f98-4e7c-82f7-b5ec805b53f6}

I tried making it a POST and then it does not malform the URL, but obviously it doesn't work because it needs to be a PUT. I have debugged and I am saving the cookie and id data correctly.

Just in case here are my libraries:

compile 'com.squareup.retrofit:retrofit:2.0.0-beta4'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile 'com.squareup.okhttp3:mockwebserver:3.0.1'

compile 'com.squareup.okio:okio:1.6.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-moshi:2.0.0-beta2'
compile 'com.squareup:seismic:1.0.2'

EDIT:
Logcat:

D/OkHttp: --> PUT /api/User/f475b862-xxxx-xxxx-a1e7-3309d5f2be11 HTTP/1.1 03-14 11:02:45.905 25738-26269/app.com D/OkHttp: Cookie: .AspNet.MyCookieMiddlewareInstance=cookiedata; path=/; httponly
03-14 11:02:45.905 25738-26269/app.com D/OkHttp: {"email":"user@email.com","id":"f475b862-xxxx-xxxx-a1e7-3309d5f2be11","name":"Joe Soap","password":"...."}
03-14 11:02:45.905 25738-26269/app.com D/OkHttp: --> END PUT (124-byte body)
03-14 11:02:45.930 25738-25796/app.com W/EGL_emulation: eglSurfaceAttrib not implemented
03-14 11:02:45.930 25738-25796/app.com W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa0171a00, error=EGL_SUCCESS
03-14 11:02:47.748 25738-26269/app.com D/OkHttp: <-- HTTP/1.1 404 Not Found (1842ms)
03-14 11:02:47.748 25738-26269/app.com D/OkHttp: Server: nginx/1.4.6 (Ubuntu)
03-14 11:02:47.748 25738-26269/app.com D/OkHttp: Date: Mon, 14 Mar 2016 08:58:02 GMT
03-14 11:02:47.748 25738-26269/app.com D/OkHttp: Content-Type: text/html
03-14 11:02:47.748 25738-26269/app.com D/OkHttp: Transfer-Encoding: chunked
03-14 11:02:47.748 25738-26269/app.com D/OkHttp: Connection: keep-alive
03-14 11:02:47.748 25738-26269/app.com D/OkHttp: OkHttp-Selected-Protocol: http/1.1
03-14 11:02:47.748 25738-26269/app.com D/OkHttp: OkHttp-Sent-Millis: 1457946167561
03-14 11:02:47.748 25738-26269/app.com D/OkHttp: OkHttp-Received-Millis: 1457946167747
03-14 11:02:47.749 25738-26269/app.com D/OkHttp: <-- END HTTP (177-byte body)

From here it looks like it is formatting the URL correctly, but when I get the response object from RetroFit it is all garbled.

1 Answers
Related