Description: New HTTP Client cannot send numbers in post form
Server Code: Just returning post data and header info
Place in ~/Sites folder, named 'server.php'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: X-Requested-With, Origin, X-Titanium-Id, Content-Type, Accept');
$data = $_POST;
echo json_encode($data);
echo json_encode((object) array('header' => apache_request_headers()));
?>
Client Code: update the URLs with your own username
var xhr = Ti.Network.createNewHTTPClient({
onload: function(e) {
//alert(this.responseData);
Ti.API.info('New HTTP Client');
Ti.API.info(JSON.stringify(this.responseData));
Ti.API.info(JSON.stringify(this.responseText));
},
onerror: function(e) {
Ti.API.error(e.error);
}
});
//xhr.setRequestHeader('Content-Type', 'multipart/form-data');
xhr.open('POST', 'http://localhost/~your_name/server.php');
xhr.send({
"test[0]":1,
"test[1]":2,
foo: 'foobar',
array: [1,2,3]
});
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
Ti.API.info('Old HTTP Client');
Ti.API.info(JSON.stringify(this.responseData));
Ti.API.info(JSON.stringify(this.responseText));
},
onerror: function(e) {
Ti.API.error(e.error);
}
});
xhr.open('POST', 'http://localhost/~your_name/server.php');
xhr.send({
"test[0]":1,
"test[1]":2,
foo: 'foobar',
array: [1,2,3]
});
Sample Log Output:
[INFO] : New HTTP Client
[INFO] : {}
[INFO] : "{\"foo\":\"foobar\",\"array\":\"[1,2,3]\"}
{\"header\":{\"Host\":\"localhost\",\"X-Titanium-Id\":\"7f8e8b5a-d939-4fff-8671-c656f18605e5\",\"X-Requested-With\":\"XMLHttpRequest\",\"Content-Type\":\"application\\/x-www-form-urlencoded; charset=utf-8\",\"Accept\":\"*\\/*\",\"Content-Length\":\"32\",\"Connection\":\"keep-alive\",\"Accept-Language\":\"en-us\",\"Accept-Encoding\":\"gzip, deflate\",\"User-Agent\":\"Appcelerator Titanium\\/3.3.0.v20140304134105 (iPhone Simulator\\/7.0.3; iPhone OS; en_US;)\"}}"
[INFO] : Old HTTP Client
[INFO] : {}
[INFO] : "{\"foo\":\"foobar\",\"test\":[\"1\",\"2\"],\"array\":\"(\\n 1,\\n 2,\\n 3\\n)\"}
{\"header\":{\"Host\":\"localhost\",\"X-Titanium-Id\":\"7f8e8b5a-d939-4fff-8671-c656f18605e5\",\"X-Requested-With\":\"XMLHttpRequest\",\"Accept-Encoding\":\"gzip\",\"Content-Type\":\"application\\/x-www-form-urlencoded; charset=utf-8\",\"Content-Length\":\"108\",\"Connection\":\"close\",\"User-Agent\":\"Appcelerator Titanium\\/3.3.0.v20140304134105 (iPhone Simulator\\/7.0.3; iPhone OS; en_US;)\"}}"
PR: https://github.com/appcelerator/titanium_mobile/pull/5433
Verified the issue with: Appc-Studio:3.3.0.201405011408 sdk:3.3.0.v20140506145022 acs:1.0.14 alloy:1.4.0-dev npm:1.3.2 titanium:3.3.0-dev titanium-code-processor:1.1.1 xcode:5.1.1 Getting below mentioned error:
Hence Reopening the issue.
The test case has changed. Ti.Network.createNewHTTPClient was a temporary testing object. Use Ti.Netowrk.createHTTPClient instead.
Reopening the issue as not getting the expected output: Appc-Studio:3.3.0.201405121247 sdk:3.3.0.v20140512162513 acs:1.0.14 alloy:1.4.0-dev npm:1.3.2 titanium:3.3.0-dev titanium-code-processor:1.1.1 xcode:5.1.1 Device:IphoneSimulator(v7.1) Used the below code:
Actual Result:
Expected Result:
Verified fixed on: Mac OSX 10.9.3 Appcelerator Studio, build: 3.3.0.201405121247 Titanium SDK, build: 3.3.0.v20140515133312 Titanium CLI, build: 3.3.0-dev Alloy: 1.4.0-alpha Spoke with Pedro, and the new expected outcome is:
Closing.