Titanium Community Questions & Answer Archive

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

Cookie and Post params by HTTPClient

Hello. I have two troubles with HTTPClient:

Simple code:

var client = Titanium.Network.createHTTPClient()
client.onerror = function(e)
{
    Ti.API.info("ERROR " + e.error);
};

client.onreadystatechange = function() {
  if (this.readyState == 4) {
    var cookie = this.getResponseHeader("set-cookie");
    alert(cookie);
  }
};
client.open("POST", "http://localhost:3000/signin");
client.send({login:'mylogin', password:'mypassword'});

My Server listen this like MULTIPART_FORM

Processing by SessionsController#create as MULTIPART_FORM
  Parameters: {"login"=>#<File:/var/folders/+J/+JPihIMPFO0uuM9HEIP0aU+++TI/-Tmp-/RackMultipart20100408-42743-kb3fix-0>, "password"=>"[FILTERED]"}

After when I add some like this:

client.setRequestHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8");

and change client.send to:

client.send('login=mylogin&password=mypassword')

this start working, but second problem with getting session data - in headers I will receive only first session parameter but second with contains important data for me i can't receive.
And important note: in browser from JavaScript function this some code with XMLHttpRequest instead of HTTPClient work fine, and get all cookie.
P.S. - platform android

— asked April 8th 2010 by Andriy Bazyuta
  • android
  • cookie
  • httpclient
0 Comments

5 Answers

  • Hey Andriy

    Not sure if this is the cause of the problem, but you're using all lower-case HTTP header names, you might try switching around the case. i.e, try:

    this.getResponseHeader('Set-Cookie');
    

    You might also switch content-type to Content-Type

    — answered April 8th 2010 by Marshall Culpepper
    permalink
    1 Comment
    • I am having the same issue. I want to access the Content-type and Content-dosposition headers, but only get back NULL. I tried this.getResponseHeader('Content-disposition') and e.getResponseHeader('Content-disposition') inside onload, both come back empty. I confirmed that Content-disposition is being set by my server side code. BTW, 'Content-type' also doesnt work. I really need to get this working. Any help?

      — commented August 15th 2010 by Ben Hornedo
  • with case getResponseHeader("Set-Cookie") and Content-Type - same result - not successful..((

    — answered April 8th 2010 by Andriy Bazyuta
    permalink
    0 Comments
  • You need to use the correct http header Set-Cookie

    perhaps the following helps:
    http://www.tine20.org/forum/viewtopic.php?f=12&t=4608&p=18980#p18980

    — answered November 16th 2010 by Kay Strobach
    permalink
    0 Comments
  • with case getResponseHeader("Set-Cookie") and Content-Type - same result - not successful..((

    — answered April 8th 2010 by Andriy Bazyuta
    permalink
    0 Comments
  • Same question here, I can't get any header data by using getHeaderResponse:

    xhr.onreadystatechange = function() {
    if (this.readyState == 4) {
    var cookie = this.getResponseHeader("Server");
    alert('header ' + server);
    }
    }

    alert: header null

    — answered April 10th 2010 by sdf ksdf
    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.