Titanium Community Questions & Answer Archive

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

HTTPClient not sending data via GET right

I'm trying to get the response from http://example.com/some/path/?foo=bar.

I've tried this:

var url = "http://example.com/some/path/";
xhr.open("GET",url);
xhr.onload = function(userLocation) { Ti.APP.info('In onload'); }
xhr.send({foo:'bar'});

and

var url = "http://example.com/some/path/";
xhr.open("GET",url);
xhr.onload = function(userLocation) { Ti.APP.info('In onload'); }
var data = {};
data.foo = 'bar';
xhr.send(Ti.JSON.stringify(data));

And I even tried:

var url = "http://example.com/some/path/?foo="+'bar';
xhr.open("GET",url);
xhr.onload = function(userLocation) { Ti.APP.info('In onload'); }
xhr.send({foo:'bar'});

None of these approaches seems to work? This has to be something stupid I'm doing or this is another one of those QA things missed in 1.3. Any advice?

— asked June 17th 2010 by Anthony Bibbs
  • data
  • get
  • httpclient
  • mobile
0 Comments

3 Answers

  • This works for me:

     var url = 'http://' + saved_ip_address + '/control.php?network=' + network + '&action=' + action;
     var ConnectionAction = Ti.Network.createHTTPClient();
           ConnectionAction.open("GET", url);
           ConnectionAction.send();
    

    In this case, I don't care about the response, but you can just add:

    ConnectionAction.onload = function() { 
         alert(this.response);
    }
    

    If you want to do something with it…

    — answered June 18th 2010 by Ken Bantoft
    permalink
    0 Comments
  • You have to put your request in "POST" because you send parameters

    — answered June 17th 2010 by Guillaume LAFOUTRY
    permalink
    1 Comment
    • The REST service I'm calling won't respond to POST, only GET. There has to be a way to do this. This is as elementary as it gets.

      — commented June 17th 2010 by Anthony Bibbs
  • What was the answer to this? I have the same behaviour - I am specifying "GET" but it is always using "POST". This indeed is elementary - please point me in the right direction…

    — answered July 24th 2011 by Matthew Delmarter
    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.