AFNetworking - does its HTTP request send with cookies by default? - ios5

I am trying to debug a http get request i sent via AFNetworking's AFJSONRequestOperation to see if the cookies are being sent correctly. However, i dont see any cookies in http header. Can some expert help me out here? thanks! :)

You can set the cookie to your AFHTTPClient or it's subclass with the following line
[_httpClient setDefaultHeader:#"Cookie" value:#"cookie=value"];
I've tried this with my server and it works. It can clearly catch the cookie named cookie and it's related value.

Related

WKWebView can't carry cookie for 302 redirect

I set cookie in request header before I call loadRequest() function to load a page. I also use document.cookie() to set cookie by WKUserScript according to [WKWebView Cookies. However, I find that if a 302 redirection occurs, request may fail for loss of cookie. For example, the request of http://A redirect to http://B, I could set cookie for request of http://A by operating request head and using WKUserScript, but these two ways can not set cookie for request of http://B, so the 302 request of http://B may fail. This situation occurs in ios8 more frequently than ios9. Does anybody have a workaround?
Note sure, but probably the first response may contain "Set-Cookie" header. Hence, you have to use the provided cookie in the second request. May be it's missing.
workaround for set cookies in iOS please check my answer. You must set cookies both in request and wkuserscript same time. otherwise it fail one time and sucess in 2nd run,
Can I set the cookies to be used by a WKWebView?

Cannot set HTTP request body

Can anyone tell me how to send a file to server and a username. I tried to set HTTP body with the content of the file and use GET method to set username but it doesn't work and encounter the exact situation as this post:( this is a bug) :
NSURLRequest cannot handle HTTP body when method is not POST?
As the post says, can anyone show me how to use PUT method as in both the ios client and php server or show me another method ?

ASIHTTPRequest returns error 406 when trying to read RSS Feed

I'm trying to read the following URL: http://www.bandsintown.com/Godwrath/rss
My response string is empty and [request responseStatusCode] returns 406. I've tried adding the following with no success:
[request addRequestHeader:#"Accept" value:#"text/xml"];
[request addRequestHeader:#"Accept" value:#"application/rss+xml"];
Have any of you ever bumped into this problem?
Greets,
Shai.
Use CharlesProxy (or wireshark, or ...) to capture the http traffic from:
Your iOS app
A working client (eg. a web browser)
Compare the 2 and try to correct any differences (you can probably ignore User-Agent:, Connection:, If-Modified-Since: and a few other headers)
If you still can't get it working edit your question to add in the request captured in charlesproxy from the browser, your changed code to create the request and the request captured from your app.
406 generally means your browser doesn't understand the return data from the web server. In the example you give, you overwrite the Accept header. You can't provide the same header tag twice if I remember correctly...

Don't get all cookies from NSHTTPURLResponse or NSHTTPCookieStorage

I'm trying to programmatically submit a form using a NSURLConnection.
To make sure I get the proper response when sending the form, I collect the form using an NSURLConnection, collect all the cookies from the corresponding NSHTTPURLResponse, scrape the form, fill it out and resubmit it to the web server with the cookies from the NSHTTPURLResponse.
However, I've noticed that neither NSHTTPCookieStorage nor the NSHTTPURLResponse have all the cookies that the web server is sending back.
I've compared the contents of the following two methods [[NSHTTPURLResponse allHeaderFields] valueForKey:#"Set-Cookie"] and [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] to the response seen through a web proxy and simply telnet.
The response seen through the web proxy and telnet show all the same "Set-Cookie" fields.
The string from NSHTTPURLResponse and array from NSHTTPCookieStorage neither agree with one another nor the results from the web proxy/telnet. Can someone suggest why that might be?
Thanks,
Jason Mazzotta

Set the certification to the NSHTTPURLResponse in iPhone

I would like to send some information to a 'HTTPS' server and get the cookies and html code from the server. I have already complete the cookies and the html part. However, when I use the 'GET' method to set the url and use the statusCode to see the http status code, I found that the status code is 0. I found the error is about the 'untrust server certificate'.
How can I add the certificate to the NSHTTPURLResponse in order to receive the 200 or 302 status code? The error display the Error Code = -1202. Thank you.
I had the same problem a few days ago, the following post solved it.
Adding an untrusted certificate is (at least in the simulator) not possible, but you can tell your NSURLConnection Delegate to accept self signed certificates (or generally untrusted ones)
How to use NSURLConnection to connect with SSL for an untrusted cert?
hope I could help!