Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18902] HTTPClient: unable set content-type as json for multipart post request using Httpclient

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-08-07T19:12:16.000+0000
Affected Version/sRelease 3.5.1, Release 4.0.0
Fix Version/sRelease 4.1.1, Release 5.0.0
ComponentsAndroid, iOS
Labelsheader, httpclient, mutipart
ReporterShuo Liang
AssigneeChee Kiat Ng
Created2015-05-13T14:13:28.000+0000
Updated2016-08-18T08:06:40.000+0000

Description

Description:

HTTP request sends post to a Salesforce.com REST api that is expecting a multipart request with content-type set clearly for each of the parts, like the following: {quote} POST /services/data/v33.0/chatter/feed-elements HTTP/1.1 Authorization: OAuth 00DRR0000000N0g!... User-Agent: Jakarta Commons-HttpClient/3.0.1 Host: instance_name Content-Length: 845 Content-Type: multipart/form-data; boundary=boundary Accept: application/json --boundary Content-Disposition: form-data; name="json" Content-Type: application/json; charset=UTF-8 { "somejson":"data" } --boundary Content-Disposition: form-data; name="feedElementFileUpload"; filename="receipt.pdf" Content-Type: application/octet-stream; charset=ISO-8859-1 filecontent {quote} If we set xhr.setRequestHeader("enctype", "multipart/form-data"), This is fine for the file part, as Titanium is doing the magic. However, for the json part, Titanium will not set it and hence caused parsing errors for the post request. How can we support that?

Attachments

FileDateSize
testServer.js2015-07-15T04:39:20.000+0000223

Comments

  1. Eddie Wu 2015-05-16

    Hi is there a fix plan or ETA? Many thanks.
  2. Chee Kiat Ng 2015-07-03

    [~sliang], Just to check before we investigate further, in the sample code, it should be an array as a parameter in
       xhr.send(array)
       
    right?

    It should be:

       xhr.send([data2send]);
       
  3. Eddie Wu 2015-07-03

    @Chee Kiat Ng, not exactly - according to the document - http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient-method-send
       Parameters
       data : Object/String/Titanium.Filesystem.File/Titanium.Blob (optional)
       Data to send with a POST request.
       
  4. Ashraf Abu 2015-07-15

    Android PR: https://github.com/appcelerator/titanium_mobile/pull/6976 Node JS server code [^testServer.js] also attached here. For testing instructions, check PR in Github.
  5. Ashraf Abu 2015-07-15

    [~hpham] Could you review the above PR?
  6. Ashraf Abu 2015-07-22

    Reopening issue as iOS is not completed yet. [~cng] Android PR has been merged.
  7. Chee Kiat Ng 2015-07-29

    iOS PRs done: https://github.com/appcelerator/titanium_mobile/pull/6991 https://github.com/appcelerator/APSHTTPClient/pull/27
  8. Chee Kiat Ng 2015-08-04

    PRs updated again, so that change is only applied to content-type for multipart post. The rest of the behavior remains the same.
  9. Ashraf Abu 2015-08-06

    Android Backport to 4_1_X: https://github.com/appcelerator/titanium_mobile/pull/7009 [~hpham] For your review.
  10. Chee Kiat Ng 2015-08-06

    iOS backport to 4_1_X: https://github.com/appcelerator/titanium_mobile/pull/7010 [~pec1985], For your review and merge.
  11. Chee Kiat Ng 2015-08-13

    all outstanding PRs merged.
  12. Eric Wieber 2015-08-25

    Verified fixed, using: MacOS 10.11 (15A263e) Studio 5.0.0.201508181557 Ti SDK 4.1.1.v20150816214206 Appc NPM 4.2.0-1 Appc CLI 4.1.3-6 Ti CLI 4.0.1 Alloy 1.6.2 Arrow 1.2.38 Xcode 6.4 (6E35b) Node v0.10.37 Java 1.7.0_45 preproduction Successfully get expected JSON return from sample code on Android and iOS

JSON Source