Problems creating a POST in HTTPClient - mobile, android

You must Login before you can answer or comment on any questions.

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 4 years ago by Josh Orchard
1 Comment
  • Which log statements in the above are you able to see?

    — commented 4 years ago by Kevin Whinnery

1 Answer

Try setting the content type:

xhr2.setRequestHeader("Content-Type","text/xml; charset=utf-8");

Your Answer

Think you can help? Login to answer this question!