Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13275] Android: HTTPClient not sending POST vars

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionInvalid
Resolution Date2013-03-29T21:07:59.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 07 API, 2013 Sprint 07
ComponentsAndroid
LabelsHttpClient, android, ipass1, sdk2.1.4, triage
ReporterPatrick Jongmans
AssigneeJoshua Quick
Created2012-11-15T15:47:11.000+0000
Updated2018-08-06T17:37:06.000+0000

Description

When using the current SDK 2.1.4 the POST DATA is not sending on Android. A normal json format post is being send:
    //THIS IS NOT RECEIVED ON THE SERVER (ONLY ANDROID) ---
    var orderOptions = {};
    orderOptions.username = 'USERNAME';
    orderOptions.password = 'PASSWORD';
    orderOptions.somevar  = 'Some data';

    var client = Ti.Network.createHTTPClient({
		onload : function(e) {
			
    		}
			
        },
        onerror : function(e) {
        	
        	if(errorCallback != null) {
    			errorCallback(false);
    		}

        },
        timeout : 5000
	});
	
    client.open("POST", 'http://www.somedomain.com/afile.php');
    client.setRequestHeader('Content-Type', 'text/html; charset=utf-8;');
    client.send(orderOptions);

Comments

  1. Francis Meetze 2012-12-27

    Is this issue being escalated? Reference: http://developer.appcelerator.com/question/146006/google-app-engine-seems-to-confuse-android-post-with-get-over-httpclient#answer-253222
  2. Pedro Enrique 2013-03-29

    Tested this and confirming bug. (works as expected on android)

    Code on my server:

       <?php 
          header('Content-Type: text/html; charset=utf-8');
       ?>
       
       { username: "<?php echo $_POST["username"]; ?>", password: "<?php echo $_POST["password"]; ?>" }
       

    Titanium code:

       var win = Ti.UI.createWindow({
       	backgroundColor: 'white'
       });
       
       var btn = Ti.UI.createButton({
       	title: 'here'
       });
       
       win.add(btn);
       
       win.open();
       
       btn.addEventListener('click', function(){
       	var xhr = Ti.Network.createHTTPClient();
       	xhr.onload = function() {
       		alert(this.responseText);
       	}
       	xhr.onerror = function() {
       		alert(this.responseText);
       	}
       	xhr.open('POST', 'http://pec1985.com/me/test.php');
       
       	xhr.setRequestHeader('Content-Type', 'text/html; charset=utf-8;');
       	
       	xhr.send({
       		username: 'some_user_name',
       		password: 'some_password'
       	});
       });
       

    Expected response from server:

       { username: "some_user_name", password: "some_password" }
       

    Real response from server on Android

       { username: "", password: "" }
       
  3. Pedro Enrique 2013-03-29

    Same happens on 3.0.2.GA
  4. Vishal Duggal 2013-03-29

    [~penrique] Shouldn't the content type signify form encoded data (eg:application/x-www-form-urlencoded). Can you retry with the new content type.
  5. Vishal Duggal 2013-03-29

    Resolving this as invalid since I suspect this is due to the wrong content type. If it is not so, please reopen ticket.
  6. Francis Meetze 2013-04-23

    It would be great if this was re-opened. There seems to be some intermittent issues with the POST method being confused with GET and that is why the POST parameters aren't being received properly. I am able to duplicate this with applications running with the latest Android ICS OS. Something this simple: xhr.open('POST', 'http://www.some-web-site.com/mobileupdate/masterstack'); xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); xhr.send(); Although no data is being sent in this example, it should still be read as a POST. It is not: [22/Apr/2013:16:58:06 -0700] "GET /mobileupdate/masterstack/ HTTP/1.1" 200 146036 - - "www.my_website.com" ms=58 cpu_ms=21 cpm_usd=0.016321 app_engine_release=1.7.7 However, the POST works fine on devices running Gingerbread. See reference: http://developer.appcelerator.com/question/146006/google-app-engine-seems-to-confuse-android-post-with-get-over-httpclient Titanium 3.1; SDK 3.0.2.GA
  7. Eric Merriman 2017-03-28

    [~jquick] Could you see if the POST is working as expected for you.
  8. Eric Merriman 2018-08-06

    Closing as invalid. If incorrect, please reopen.

JSON Source