Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Problems creating a POST in HTTPClient - mobile, android

I have been developing a mobile application and things were going well. I can download data from the server and render as needed.

I know need to grab a page from the web server. Modify the DOM and then post back the information. basically act as the browser but limit what the user may alter on the page. I have been able to get the page. Place in a DomDocument and alter the contents with the mobile UI.

Now in the onload of the first httpclient I want to create a second httpclient and send back the changes of the modified Dom as a POST. The HTTPClient is not even trying to connect to the server. I have a tunnel set up and no attempt to connect to the server is being made. Is it possible to new second HTTPClient in the onload section of first HTTPClient? Is this a known issue or is there some other way that I should be construction the post? Below is the section that is not working. I know there is an issue with reusing the HTTPClient to maintain cookies and headers and look forward to that being fixed.

It appears after a long timeout it does return a timeout. The readystate of the HTTPClient never gets past 1.

code:

var xhr = Ti.Network.createHTTPClient();
xhr.onload = function()
{
// did some other code above this to get values
var xml = someDataAbove;

  submitButton.addEventListener ('click',function(buttonFunction){

    var xhr2 = Ti.Network.createHTTPClient();
    xhr2.onload = function()
    {
    Titanium.API.info('IN ONLOAD ' + this.status + ' readyState ' + this.readyState);
    var newWebPage = xhr2.responseText;
    Titanium.API.info("***newWebPage: "+newWebPage);
    };

    xhr2.onerror = function(e)
    {
    Titanium.API.info('IN ERROR ' + e.error);
    };

    xhr2.open("POST","http://198.168.1.105:8888/index.php");

    xhr2.send(xml);

  }); 
}
xhr.open("GET",loginURL);
xhr.send();
— asked June 1st 2010 by Josh Orchard
  • android
  • httpclient
  • mobile
1 Comment
  • Which log statements in the above are you able to see?

    — commented June 1st 2010 by Kevin Whinnery

1 Answer

  • Try setting the content type:

    
    xhr2.setRequestHeader("Content-Type","text/xml; charset=utf-8");
    
    — answered January 11th 2012 by Jesus Duarte
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.