Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16557] iOS: NewHTTPClient not able to send numbers as post data

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-05-13T16:44:26.000+0000
Affected Version/sRelease 3.3.0
Fix Version/s2014 Sprint 05, 2014 Sprint 05 API, Release 3.3.0
ComponentsiOS
Labelsmodule_network, qe-testadded
ReporterPedro Enrique
AssigneePedro Enrique
Created2014-03-05T21:49:48.000+0000
Updated2014-06-19T12:44:28.000+0000

Description

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;)\"}}"

Comments

  1. Pedro Enrique 2014-03-05

    PR: https://github.com/appcelerator/titanium_mobile/pull/5433
  2. Priya Agarwal 2014-05-07

    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:
       [WARN] :   Attempted to load TiNetworkNewHTTPClientProxy: Could not find class definition.
       [ERROR] :  Script Error {
        backtrace = "#0 () at :0";
       [ERROR] :      line = 10;
       [ERROR] :      message = "invalid method (createNewHTTPClient) passed to NetworkModule";
       [ERROR] :      sourceId = 299248096;
       [ERROR] :      sourceURL = "file:///Users/p.agarwal/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/1738C242-6A30-44F0-A4D1-20165EF81961/hello.app/app.js";
       [ERROR] :  }
       
    Hence Reopening the issue.
  3. Pedro Enrique 2014-05-12

    The test case has changed. Ti.Network.createNewHTTPClient was a temporary testing object. Use Ti.Netowrk.createHTTPClient instead.
  4. Priya Agarwal 2014-05-13

    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:
       var xhr = Ti.Network.createHTTPClient({
           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]
       });
        
       
       
    Actual Result:
       New HTTP Client
       [INFO] :   {}
       [INFO] :   "{\"foo\":\"foobar\",\"test\":[\"1\",\"2\"],\"array\":\"(\\n    1,\\n    2,\\n    3\\n)\"}{\"header\":{\"Host\":\"localhost\",\"X-Titanium-Id\":\"6a991287-98f3-4679-9faa-ab7c65199abd\",\"X-Requested-With\":\"XMLHttpRequest\",\"Accept\":\"*\\/*\",\"Content-Type\":\"application\\/x-www-form-urlencoded; charset=utf-8\",\"Content-Length\":\"84\",\"Accept-Language\":\"en-us\",\"Accept-Encoding\":\"gzip, deflate\",\"Connection\":\"keep-alive\",\"User-Agent\":\"Appcelerator Titanium\\/3.3.0 (iPhone Simulator\\/7.1; iPhone OS; en_US;)\"}}"
       
    Expected Result:
       [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;)\"}}"
       
  5. Samuel Dowse 2014-05-16

    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:
       [INFO] :   New HTTP Client
       [INFO] :   {}
       [INFO] :   "{\"foo\":\"foobar\",\"test\":[\"1\",\"2\"],\"array\":\"(\\n    1,\\n    2,\\n    3\\n)\"}{\"header\":{\"Host\":\"localhost\",\"X-Titanium-Id\":\"97f5e3cd-c752-400e-b9ad-ac692cab8429\",\"X-Requested-With\":\"XMLHttpRequest\",\"Accept\":\"*\\/*\",\"Content-Type\":\"application\\/x-www-form-urlencoded; charset=utf-8\",\"Content-Length\":\"84\",\"Accept-Language\":\"en-us\",\"Accept-Encoding\":\"gzip, deflate\",\"Connection\":\"keep-alive\",\"User-Agent\":\"Appcelerator Titanium\\/3.3.0 (iPhone Simulator\\/7.1; iPhone OS; en_US;)\"}}"
       
    Closing.

JSON Source