{ "id": "104838", "key": "TIMOB-13357", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2012-11-12T17:36:02.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "form-encoded", "httpclient", "post" ], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-02-28T20:03:38.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "When using the HTTPClient in Titanium Mobile, the documentation (http://docs.appcelerator.com/titanium/2.1/#!/api/Titanium.Network.HTTPClient-method-send) says that if you pass a serializable JavaScript object, it will automatically turn it into form-encoded POST data. However, this breaks when your data contains an array.\r\n\r\nUsing the free service httpbin (http://httpbin.org/) to view the POST data that is sent, you can see that the array is not properly encoded. By sending POST data to httpbin.org/post, we can see the POST data that Titanium sends.\r\n\r\nExample code: \r\n\r\n{code:js}\r\nvar xhr = Ti.Network.createHTTPClient();\r\nxhr.onload = function(ev) {\r\n Ti.API.info(this.responseText);\r\n};\r\nxhr.open('POST','http://httpbin.org/post');\r\nxhr.send({\r\n 'test_text': 'testing',\r\n 'test_array': ['one','two','three']\r\n});\r\n{code}\r\n\r\nThe response received looks like this:\r\n\r\n{code}\r\n{\r\n \"files\": {},\r\n \"form\": {\r\n \"test_array\": \"[Ljava.lang.Object;@41a6e560\",\r\n \"test_text\": \"testing\"\r\n },\r\n \"url\": \"http://httpbin.org/post\",\r\n \"args\": {},\r\n \"headers\": {\r\n \"Content-Length\": \"63\",\r\n \"Connection\": \"keep-alive\",\r\n \"User-Agent\": \"\",\r\n \"Host\": \"httpbin.org\",\r\n \"X-Requested-With\": \"XMLHttpRequest\",\r\n \"Content-Type\": \"application/x-www-form-urlencoded\"\r\n },\r\n \"json\": null,\r\n \"data\": \"\"\r\n}\r\n{code}\r\n\r\nYou will see the \"test_array\" has a value of \"[Ljava.lang.Object;@41a6e560\".\r\n\r\nHowever, sending the data as a url encoded string by changing the send statement to this:\r\n\r\n{code:js}\r\nxhr.send('test_text=testing&test_array=one&test_array=two&test_array=three');\r\n{code}\r\n\r\nCreates the correct post data:\r\n\r\n{code}\r\n{\r\n \"origin\": \"64.128.22.8\",\r\n \"files\": {},\r\n \"form\": {\r\n \"test_array\": [\r\n \"one\",\r\n \"two\",\r\n \"three\"\r\n ],\r\n \"test_text\": \"testing\"\r\n },\r\n \"url\": \"http://httpbin.org/post\",\r\n \"args\": {},\r\n \"headers\": {\r\n \"Content-Length\": \"64\",\r\n \"Connection\": \"keep-alive\",\r\n \"User-Agent\": \"\",\r\n \"Host\": \"httpbin.org\",\r\n \"X-Requested-With\": \"XMLHttpRequest\",\r\n \"Content-Type\": \"application/x-www-form-urlencoded\"\r\n },\r\n \"json\": null,\r\n \"data\": \"\"\r\n}\r\n{code}", "attachment": [], "flagged": false, "summary": "Android: Titanium does not properly handle arrays in form-encoded POSTs", "creator": { "name": "matt.baxter@projekt202.com", "key": "matt.baxter@projekt202.com", "displayName": "Matt Baxter", "active": true, "timeZone": "America/Chicago" }, "subtasks": [], "reporter": { "name": "matt.baxter@projekt202.com", "key": "matt.baxter@projekt202.com", "displayName": "Matt Baxter", "active": true, "timeZone": "America/Chicago" }, "environment": "Titanium Mobile SDK 2.1.3, Android", "comment": { "comments": [ { "id": "253656", "author": { "name": "aodev", "key": "aodev", "displayName": "Kevin Purnelle", "active": true, "timeZone": "Europe/Berlin" }, "body": "I had the same problem. @matt Thanks for the current tip to solve this problem :)\r\n\r\nhttp://developer.appcelerator.com/question/152751/how-can-i-see-the-request-headers-in-http-client-along-with-the-post-message--httpclient-problem#answer-263243", "updateAuthor": { "name": "aodev", "key": "aodev", "displayName": "Kevin Purnelle", "active": true, "timeZone": "Europe/Berlin" }, "created": "2013-05-23T16:32:13.000+0000", "updated": "2013-05-23T16:32:13.000+0000" }, { "id": "284513", "author": { "name": "wpccolorblind", "key": "wpccolorblind", "displayName": "josh rose", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Just hit this as well and finally realized it was this bug after a bunch of debugging.\r\n\r\nThis seems like an important scenario (Android + POSTing and array) in an essential module.\r\n\r\nAny chance this can get some traction after a year of being an issue?", "updateAuthor": { "name": "wpccolorblind", "key": "wpccolorblind", "displayName": "josh rose", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-12-16T19:20:02.000+0000", "updated": "2013-12-16T19:20:02.000+0000" }, { "id": "284524", "author": { "name": "wpccolorblind", "key": "wpccolorblind", "displayName": "josh rose", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Thanks Ingo!", "updateAuthor": { "name": "wpccolorblind", "key": "wpccolorblind", "displayName": "josh rose", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-12-16T19:56:05.000+0000", "updated": "2013-12-16T19:56:05.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }