Retrofit & Http Patch
So I want to make a PATCH request using Retrofit but currently I cannot add okhttp to my classpath. When I attempt to make a PATCH request I get the stack trace below. Is there any
Solution 1:
This is a limitation of HttpUrlConnection
. You can either use Apache or OkHttp which both support PATCH
as an alternative client. This can be done explicitly in the builder:
RestAdapterrestAdapter=newRestAdapter.Builder()
.setEndpoint(..)
.setClient(newOkClient())
.build()
Additionally, some servers allow specifying an X-HTTP-Method-Override
header for changing the method. With this you would send a POST
but include PATCH
as this header value. Again, this requires server support.
Finally, one other option would be to subclass Retrofit's UrlConnectionClient
and use reflection to change the field which holds the HTTP method. This is very fragile, prone to future breakage, and is the worst option in my opinion.
Post a Comment for "Retrofit & Http Patch"