[TIMOB-18902] HTTPClient: unable set content-type as json for multipart post request using Httpclient
GitHub Issue | n/a |
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-08-07T19:12:16.000+0000 |
Affected Version/s | Release 3.5.1, Release 4.0.0 |
Fix Version/s | Release 4.1.1, Release 5.0.0 |
Components | Android, iOS |
Labels | header, httpclient, mutipart |
Reporter | Shuo Liang |
Assignee | Chee Kiat Ng |
Created | 2015-05-13T14:13:28.000+0000 |
Updated | 2016-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
Hi is there a fix plan or ETA? Many thanks.
[~sliang], Just to check before we investigate further, in the sample code, it should be an array as a parameter in
right?
It should be:
@Chee Kiat Ng, not exactly - according to the document - http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient-method-send
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.
[~hpham] Could you review the above PR?
Reopening issue as iOS is not completed yet. [~cng] Android PR has been merged.
iOS PRs done: https://github.com/appcelerator/titanium_mobile/pull/6991 https://github.com/appcelerator/APSHTTPClient/pull/27
PRs updated again, so that change is only applied to content-type for multipart post. The rest of the behavior remains the same.
Android Backport to 4_1_X: https://github.com/appcelerator/titanium_mobile/pull/7009 [~hpham] For your review.
iOS backport to 4_1_X: https://github.com/appcelerator/titanium_mobile/pull/7010 [~pec1985], For your review and merge.
all outstanding PRs merged.
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