[TIMOB-19564] Android: HttpClient patch method doesn't work from 5.0.0
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Not Our Bug |
Resolution Date | 2016-03-11T08:59:52.000+0000 |
Affected Version/s | Release 5.0.0 |
Fix Version/s | Release 5.1.0 |
Components | Android |
Labels | 5.0.0.GA, android, httpclient, look1, patch |
Reporter | Aurélien HUET |
Assignee | Joshua Quick |
Created | 2015-09-18T14:58:09.000+0000 |
Updated | 2018-08-06T17:52:04.000+0000 |
Description
From release 5.0.0, the patch method doesn't work.
<sdk-version>5.0.0.GA</sdk-version>
android:targetSdkVersion="23"
android device version=4.3
CONSOLE :
[ERROR] : TiHTTPClient: (TiHttpClient-19) [18578,155345] HTTP Error (java.net.ProtocolException): Unknown method 'PATCH'; must be one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE]
[ERROR] : TiHTTPClient: java.net.ProtocolException: Unknown method 'PATCH'; must be one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE]
[ERROR] : TiHTTPClient: at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:677)
[ERROR] : TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1124)
[~aurelien.huet] Would you be able to provide the endpoint API for patch for testing? Would your endpoint respect the header
X-HTTP-Method-Override
for PATCH?Try with this URL and the body at the end (content-type=application/json) http://api.prestashop.hdb-technology.com/modules/hdbrestfulapi/api.php/v1/me/cart?_token=eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJkYXRhIjoicDhDS2tNckU2eXlaRDRiUVk5NlpiSzdyRDN5REo3QXFPU3c2bjdudVZ0djFRdDBKRDlNS1IxcWhtQVQ1dVlkS2hHeTVScm0wOVQ5K0h3YXZXVlZKOE9zTGQ5L0I4RGRKeisxNnNLUVM5a0Z2QTF2ZHBTZVlIM3RHSXRWZExxZTcxM2F4Z1VqQ3ZTRkdHcUcyb1k3LzFUZWRTTl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uiegSRCnav-a50JmC6ScjAqSlxD8WQbrddT5ujrI-BHV1n2BGg-aHZIix2be8Vdvxwu2vgM6Q-pBzKtS5-mU-Q_ShwdeBDgI2IbAkf6afvtKKllZKw18pJQ22hAnInkTk6tXQVbayMki4Feov_5eqUKVDnhChWCpdX7gp2AUaT2vmfhE8axk9r6BZXac_bXQp7lBlhyJvJvTKrC16dEQNBba6_TrCRJqk8azqBfsqo_FkIO8KgDrAwqrba9IL3XVRc8ylpzk6gPPrX-P-6WaBMcgMnURrmjpb83TvC3XdU-cVOElo7w81XbMaY-T-0EfZIdVoSfqv9BeMLNenXPKLLvtUg0DIk4pDa33A1zBZH08G5h1NGmqBHw body:{"deliver_address":27,"invoice_address":27}
Thank you [~aurelien.huet]
[~aurelien.huet] The link you send me seems down at the moment. Could you try this with the api that you want to patch.
Do change the url and the body. What's happening in this code is that it is set as POST and then a header X-HTTP-Method-Override is set to Patch. If the endpoint respects this header, it will treat it as a Patch request. Could you see if this works for you?
Ashraf Abu Here's the answer : TiHTTPClient: (TiHttpClient-2) [1078,6862] HTTP Error (java.io.IOException): 405 : METHOD NOT ALLOWED [ERROR] : TiHTTPClient: java.io.IOException: 405 : METHOD NOT ALLOWED [ERROR] : TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1213) [ERROR] : TiHTTPClient: at java.lang.Thread.run(Thread.java:841)
[~aurelien.huet] Thanks for the information!
Related Google Android ticket: https://code.google.com/p/android/issues/detail?id=76611
[~aurelien.huet] Here is a workaround. It is a module for httpclient based on OkHttp. You can download ti.okhttp-android-0.0.1.zip from here: https://github.com/ashcoding/ti.okhttp/releases To see an example, go here: https://github.com/ashcoding/ti.okhttp/blob/master/example/app.js This client allows you to upload and use the PATCH method. This client does not allow you to download any file at the moment at this initial version. For downloads, please use the normal http client. Let me know if it works for you! Resolving this ticket.
This is still broken with SDK 5.1.2GA and 5.2.0GA. Throws the following:
As a side not, how can this ticket be marked as resolved and the pull request marked as declined?
[~Mark_Boyer] Thanks for the message. This is set as resolved as it's an Android issue. https://code.google.com/p/android/issues/detail?id=76611 (Maybe a better resolution might have been
Not Our Bug
on hindsight. But there's some workaround you can do for this henceresolved
was chosen) The HttpURLConnection by Android, does not support PATCH. This can be seen in the error message you received, {quote}java.net.ProtocolException: Unknown method 'PATCH'; must be one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE]{quote} The issue ticket by Android mentioned that they are putting in PATCH in future Android versions but does not provide additional information. Is there something you need to do that requires you to do a PATCH request?Is this ever going to get fixed as a part of CORE titanium? We are currently using the OKHttp module, but I'd like to use a more uniform, native approach.
HttpURLConnection's implementation is by Android. From that I can say safely say that up till Android SDK 6 (Marshmellow) won't support Patch. As mentioned in earlier comments, https://code.google.com/p/android/issues/detail?id=76611 is the issue ticket in Android by Google that tracks this issue. That being said, I am all for a more uniform approach. If there is a better way to get this implemented, it should be investigated to improve this. Any suggestion is greatly appreciated.
Closing as "not our bug". If you disagree, please reopen.