Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Android Cookies causing a problem in HTTP POST

$
0
0

Hi guys,

I'm doing a simple HTTP POST request on my iOS app which works great, but I'm struggling with the Android version.

I've since found a reference on the Titanium docs that mentions Android stores Cookies differently to iOS.

I know the data I am sending (including my cookie) to the web API i'm using is correct, as I've tested it outside the app via a website.

So, question is, is Android trying to send lots of Cookies in my HTTP post? Which is causing the problem?

If so, which clear cookie function do I need to use first?

On Android, the HTTPClient uses its own cookie store which does not share cookies with the system cookie store used by Titanium.UI.WebView. Developers can manage their cookies for both cookie stores using the methods Titanium.Network.addHTTPCookie, Titanium.Network.addSystemCookie, Titanium.Network.getHTTPCookies, Titanium.Network.getHTTPCookiesForDomain, Titanium.Network.getSystemCookies, Titanium.Network.removeHTTPCookie, Titanium.Network.removeHTTPCookiesForDomain, Titanium.Network.removeAllHTTPCookies, Titanium.Network.removeSystemCookie, Titanium.Network.removeAllSystemCookies.
Here is my part of my HTTP POST request where I send the cookie...
// get the token
                var XCSRFToken = Ti.App.Properties.getString('XCSRFToken');
                var sessionCookie = Ti.App.Properties.getString('sessionCookie');
 
                Ti.API.info("cookie (send to upload): " + sessionCookie);
                Ti.API.info("token (send to upload): " + XCSRFToken);
 
                // set the token header
                sendImages.setRequestHeader("X-CSRF-Token", XCSRFToken);
                // set the cookie
                sendImages.setRequestHeader("Cookie", sessionCookie);
                // set the header for the correct JSON format
                sendImages.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                // send the data to the server
                sendImages.send(JSON.stringify(postImages));
Any pointers would be most welcome!

Simon


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>