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 (XHR) GET request received by server as POST

I have a very simple createHTTPClient request as follows:

var xhrTagPhoto = Ti.Network.createHTTPClient();
xhrTagPhoto.open( 'GET', 'http://server/working-server-script.php' );
xhrTagPhoto.send({
  t : 'test tag', 
  i : 1
});

On the server, however, the two sent parameters are showing up in the $_POST array while the $_GET array is empty.

How can I get these parameters to actually come across GET params?

Thanks in advance for any pointers.

— asked November 11th 2010 by Warren Harrison
  • ajax
  • get
  • httpclient
  • post
  • xhr
1 Comment
  • I worked around this by using $_POST on the server side. I gather I could also simply append the GET params in the query string. I'd still be curious to learn if I'm doing something wrong above though, or whether this is a Titanium bug.

    — commented November 11th 2010 by Warren Harrison

2 Answers

  • Accepted Answer

    I looked at the code in git hub and it appears to me that all data passed in is being set as post data when using send.

    either here…

    //body of request
    [request appendPostData:[arg dataUsingEncoding:NSUTF8StringEncoding]];
    

    or here…

    value = [TiUtils stringValue:value];
    [request setPostValue:(NSString*)value forKey:(NSString*)key];
    

    so I think without a bug fix you are going to have to append the values directly on the URL

    — answered November 11th 2010 by Aaron Saunders
    permalink
    2 Comments
    • this is still an issue with 1.7.RC1
      is anyone following up on this issue?

      — commented June 28th 2011 by John Brennan
    • I can confirm that this is still an issue in 1.7.1.

      If xhr.open() uses 'GET' and xhr.send() contains a json object, a 'GET' should be performed with the json object as a query string. But currently it is using 'POST'.

      — commented July 21st 2011 by Andy Weber
  • This should support POST, GET, PUT, DELETE. Basic stuff…

    — 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.