Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19564] Android: HttpClient patch method doesn't work from 5.0.0

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionNot Our Bug
Resolution Date2016-03-11T08:59:52.000+0000
Affected Version/sRelease 5.0.0
Fix Version/sRelease 5.1.0
ComponentsAndroid
Labels5.0.0.GA, android, httpclient, look1, patch
ReporterAurélien HUET
AssigneeJoshua Quick
Created2015-09-18T14:58:09.000+0000
Updated2018-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)

Comments

  1. Ashraf Abu 2015-09-22

    [~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?
  2. Aurélien HUET 2015-09-22

    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.eyJkYXRhIjoicDhDS2tNckU2eXlaRDRiUVk5NlpiSzdyRDN5REo3QXFPU3c2bjdudVZ0djFRdDBKRDlNS1IxcWhtQVQ1dVlkS2hHeTVScm0wOVQ5K0h3YXZXVlZKOE9zTGQ5L0I4RGRKeisxNnNLUVM5a0Z2QTF2ZHBTZVlI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bUh5jYA555rclS9S71BpjHjRj7hGXSO0J4DQNcOT7nzBpEw4nKt1I4i-uiegSRCnav-a50JmC6ScjAqSlxD8WQbrddT5ujrI-BHV1n2BGg-aHZIix2be8Vdvxwu2vgM6Q-pBzKtS5-mU-Q_ShwdeBDgI2IbAkf6afvtKKllZKw18pJQ22hAnInkTk6tXQVbayMki4Feov_5eqUKVDnhChWCpdX7gp2AUaT2vmfhE8axk9r6BZXac_bXQp7lBlhyJvJvTKrC16dEQNBba6_TrCRJqk8azqBfsqo_FkIO8KgDrAwqrba9IL3XVRc8ylpzk6gPPrX-P-6WaBMcgMnURrmjpb83TvC3XdU-cVOElo7w81XbMaY-T-0EfZIdVoSfqv9BeMLNenXPKLLvtUg0DIk4pDa33A1zBZH08G5h1NGmqBHw body:{"deliver_address":27,"invoice_address":27}
  3. Ashraf Abu 2015-09-22

    Thank you [~aurelien.huet]
  4. Ashraf Abu 2015-09-22

    [~aurelien.huet] The link you send me seems down at the moment. Could you try this with the api that you want to patch.
        
        
       var win = Ti.UI.createWindow({backgroundColor: 'white'});
        
       
       var url = "http://httpbin.org/patch?address=07645";
        
       var client = Ti.Network.createHTTPClient({
        
           // function called when the response data is available
        
           onload : function(e) {
        
               Ti.API.info("Received text: " + this.responseText);
        
               alert('success');
        
           },
        
           // function called when an error occurs, including a timeout
        
           onerror : function(e) {
        
               Ti.API.debug(e.error);
        
               alert('error');
        
           },
        
           timeout : 5000  // in milliseconds
        
       });
        
       // Prepare the connection.
        
       client.open("POST", url);
       client.setRequestHeader("X-HTTP-Method-Override", "PATCH"); 
       
       // Send the request.
       var body = {"deliver_address":27,"invoice_address":27} 
        
       client.send(body);
         
       win.open();
       
    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?
  5. Aurélien HUET 2015-09-22

    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)
  6. Ashraf Abu 2015-09-23

    [~aurelien.huet] Thanks for the information!
  7. Ashraf Abu 2015-09-25

    Related Google Android ticket: https://code.google.com/p/android/issues/detail?id=76611
  8. Ashraf Abu 2015-09-30

    [~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.
  9. Mark Boyer 2016-03-09

    This is still broken with SDK 5.1.2GA and 5.2.0GA. Throws the following:
       [ERROR] :  TiHTTPClient: (TiHttpClient-19) [13162,99993] 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:685)
       [ERROR] :  TiHTTPClient: 	at com.android.okhttp.internal.http.HttpsURLConnectionImpl.setRequestMethod(HttpsURLConnectionImpl.java:144)
       [ERROR] :  TiHTTPClient: 	at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1137)
       [ERROR] :  TiHTTPClient: 	at java.lang.Thread.run(Thread.java:841)
       [WARN] :   W/System.err: java.lang.NullPointerException
       [WARN] :   W/System.err: 	at ti.modules.titanium.network.TiHTTPClient.getAllResponseHeaders(TiHTTPClient.java:615)
       [WARN] :   W/System.err: 	at ti.modules.titanium.network.HTTPClientProxy.getAllResponseHeaders(HTTPClientProxy.java:99)
       [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeCallProperty(Native Method)
       [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.callProperty(V8Object.java:73)
       [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1155)
       [WARN] :   W/System.err: 	at android.os.Handler.dispatchMessage(Handler.java:98)
       [WARN] :   W/System.err: 	at android.os.Looper.loop(Looper.java:136)
       [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118)
       [ERROR] :  TiExceptionHandler: (main) [42,100035] ----- Titanium Javascript Runtime Error -----
       [ERROR] :  TiExceptionHandler: (main) [1,100036] - In alloy/widgets/com.rainforrent.crmdynamics/controllers/crmView.js:254,50
       [ERROR] :  TiExceptionHandler: (main) [0,100036] - Message: Uncaught Error: Java Exception occurred
       [ERROR] :  TiExceptionHandler: (main) [0,100036] - Source:                     Ti.API.info("Error: " + JSON.stringify(_evt));
       [ERROR] :  V8Exception: Exception occurred at alloy/widgets/com.rainforrent.crmdynamics/controllers/crmView.js:254: Uncaught Error: Java Exception occurred
       [WARN] :   W/System.err: java.lang.NullPointerException
       [WARN] :   W/System.err: 	at ti.modules.titanium.network.TiHTTPClient.getAllResponseHeaders(TiHTTPClient.java:615)
       [WARN] :   W/System.err: 	at ti.modules.titanium.network.HTTPClientProxy.getAllResponseHeaders(HTTPClientProxy.java:99)
       [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeCallProperty(Native Method)
       [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.callProperty(V8Object.java:73)
       [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1155)
       [WARN] :   W/System.err: 	at android.os.Handler.dispatchMessage(Handler.java:98)
       [WARN] :   W/System.err: 	at android.os.Looper.loop(Looper.java:136)
       [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118)
       
    As a side not, how can this ticket be marked as resolved and the pull request marked as declined?
  10. Ashraf Abu 2016-03-10

    [~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 hence resolved 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?
  11. Kiley Williams 2016-07-11

    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.
  12. Ashraf Abu 2016-07-12

    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.
  13. Eric Merriman 2018-08-06

    Closing as "not our bug". If you disagree, please reopen.

JSON Source