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
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
toContent-Type
-
with case getResponseHeader("Set-Cookie") and Content-Type - same result - not successful..((
-
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 -
with case getResponseHeader("Set-Cookie") and Content-Type - same result - not successful..((
-
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