Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is DELETE with a body supported? #426

Closed
loeschg opened this issue Mar 4, 2014 · 24 comments
Closed

Is DELETE with a body supported? #426

loeschg opened this issue Mar 4, 2014 · 24 comments

Comments

@loeschg
Copy link

loeschg commented Mar 4, 2014

I have an instance where I need to send a body with a DELETE. I came across this closed issue (#330) and added my own interface per @JakeWharton's suggestion.

@Target(METHOD)
@Retention(RUNTIME)
@RestMethod(value = "DELETE", hasBody = true)
public @interface MY_DELETE {
    String value();
}

When I use this method, I get the following error: java.net.ProtocolException: DELETE does not support writing

My interface method looks like this:

    @MY_DELETE("/{apiKey}/User/{userId}/MyItems/{myItemId}")
public void deleteVendor(@Path("apiKey") String apiKey,
                        @Path("userId") String userId,
                        @Path("myItemId") String myItemId,
                        @Body String payload,
                        Callback<Object> cb);

Have I implemented something wrong, or is this an issue? Any help would be fantastic. Hoping I don't have to abandon Retrofit or use another API library for just one use case.

@codefromthecrypt
Copy link

Can you influence the crafter of this api to use POST instead of DELETE? I
ran into this situation in OpenStack, filed an issue, and it was eventually
resolved.

@loeschg
Copy link
Author

loeschg commented Mar 4, 2014

@adriancole unfortunately this is not an option. I'm hitting a "legacy" api which will be replaced in the near future... though not near enough to make this something I can wait on implementing 😦.

@codefromthecrypt
Copy link

Gotcha. One way to bridge the gap is to make a Client that rewrites the
request. Basically, mark it as a POST and then catch it with your custom
client which changes it to a DELETE.

@JakeWharton
Copy link
Member

Do you know what HTTP client are you using? I can't reproduce this with UrlConnectionClient.

@loeschg
Copy link
Author

loeschg commented Mar 4, 2014

@JakeWharton Hmm... I'm not sure. I haven't specified one, so whatever the default is.

@JakeWharton
Copy link
Member

Are you on the JVM or Android?

@loeschg
Copy link
Author

loeschg commented Mar 4, 2014

Android

@JakeWharton
Copy link
Member

Ah, ok. The workaround for this is to include OkHttp's jar in your app. Since we can't change the implementation of the OS our only choice is to use a standalone HTTP client. You don't need to opt-in to using OkHttp once you add it, Retrofit will automatically find it and use it (since it's the best choice).

Can you give that a try and see if it fixes your problem?

@loeschg
Copy link
Author

loeschg commented Mar 4, 2014

I'll give that a go tomorrow and report back. Thanks for the quick responses, @JakeWharton and @adriancole

@JakeWharton
Copy link
Member

I'm going to close under the anticipation that it works. Let us know, though.

@loeschg
Copy link
Author

loeschg commented Mar 5, 2014

@JakeWharton, I added OkHttp with the following line in my gradle.build file:

compile 'com.squareup.okhttp:okhttp:1.3.+'

and I still get the following error on the DELETE request.

retrofit.RetrofitError: java.net.ProtocolException: DELETE does not support writing

Any ideas? Did I miss a step?

@JakeWharton
Copy link
Member

Paste the full stack trace please.

@loeschg
Copy link
Author

loeschg commented Mar 5, 2014

The app doesn't crash. It reaches the failure(RetrofitError error) block in the callback.

Response is null and cause is java.net.ProtocolException: DELETE does not support writing

What other info from that RetrofitError object can I provide that'd be of use?

@JakeWharton
Copy link
Member

What version of Android? I'll try to repro after lunch.
On Mar 5, 2014 11:29 AM, "Greg Loesch" notifications@github.com wrote:

The app doesn't crash. It reaches the failure(RetrofitError error) block
in the callback.

Response is null and cause is java.net.ProtocolException: DELETE does not
support writing

What other info from that RetrofitError object can I provide that'd be of
use?

Reply to this email directly or view it on GitHubhttps://github.com//issues/426#issuecomment-36782854
.

@SimonVT
Copy link

SimonVT commented Mar 5, 2014

Assuming it's this then DELETE does not allow a request body.

@JakeWharton
Copy link
Member

Ugh. What does the RFC say about it?
On Mar 5, 2014 11:34 AM, "Simon Vig Therkildsen" notifications@github.com
wrote:

Assuming it's thishttps://github.com/square/okhttp/blob/master/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpURLConnectionImpl.java#L268then DELETE does not allow a request
bodyhttps://github.com/square/okhttp/blob/master/okhttp/src/main/java/com/squareup/okhttp/internal/http/HttpMethod.java#L33
.

Reply to this email directly or view it on GitHubhttps://github.com//issues/426#issuecomment-36783484
.

@loeschg
Copy link
Author

loeschg commented Mar 5, 2014

Using Genymotion emulator 4.4.2 (Moto X model in case that's of relevance). I get the same error on a 4.2.2 device.

@SimonVT
Copy link

SimonVT commented Mar 5, 2014

The RFC is vague - you quoted it in the linked issue. Since it doesn't appear to be clear what the correct behavior is, OkHttp should probably support it.

@JakeWharton
Copy link
Member

Yeah I just clicked around it on mobile so glad to know it wasn't just me
missing it. Will move talks upstream to OkHttp internally and report back.
On Mar 5, 2014 11:46 AM, "Simon Vig Therkildsen" notifications@github.com
wrote:

The RFC is vague - you quoted it in the linked issue. Since it doesn't
appear to be clear what the correct behavior is, OkHttp should probably
support it.

Reply to this email directly or view it on GitHubhttps://github.com//issues/426#issuecomment-36784874
.

@JakeWharton
Copy link
Member

We're tracking this on OkHttp (linked above in GitHub) and it should make the impending 1.5 release in the next few days.

@loeschg
Copy link
Author

loeschg commented Mar 5, 2014

Awesome! Thanks for the update.

@loeschg
Copy link
Author

loeschg commented Mar 7, 2014

Quick work! looks like the related PR in OkHttp was closed/merged. @JakeWharton is there a slated date for the mentioned 1.5 release?

@JakeWharton
Copy link
Member

Today.

On Fri, Mar 7, 2014 at 12:53 PM, Greg Loesch notifications@github.comwrote:

Quick work! looks like the related PR in OkHttp was closed/merged.
@JakeWharton https://github.com/JakeWharton is there a slated date for
the mentioned 1.5 release?

Reply to this email directly or view it on GitHubhttps://github.com//issues/426#issuecomment-37066506
.

@loeschg
Copy link
Author

loeschg commented Mar 7, 2014

That rocks. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants