0

I have a piece of html that I render in a UIWebview. The html is stored locally, but img tags embedded in it refer to a remote server.

I would like the img request to be accompanied by two cookies that contain auth information.

I am setting [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; in my app delegate's applicationDidBecomeActive:, and I'm adding the cookies to the cookie jar in a post-login step with [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie]; (the cookie domain matches the host that serves the images).

When I debug the UIWebView with [webView stringByEvaluatingJavaScriptFromString:@"alert(document.cookie)"]; in webViewDidFinishLoad: I see an alert with the contents "/".

Firstly, why does the cookie alert contain a single slash?

Secondly, am I doing the right things to send cookies with the image request in the UIWebView?

Thanks In Advance.

TomL
  • 759
  • 8
  • 20
  • Look at this [question](http://stackoverflow.com/questions/5954382/ios-is-it-possible-to-set-a-cookie-manually-using-sharedhttpcookiestorage-for-a) – Peter Hornsby Dec 17 '15 at 16:12

1 Answers1

0

Found the problem. Changing [cookieProperties2 setObject:userId forKey:NSHTTPCookieValue]; to [cookieProperties2 setObject:[NSString stringWithFormat:@"%@",userId] forKey:NSHTTPCookieValue]; fix things.

I was expecting userId to be a string (having cast it as such), but it was in fact a long. Adding the cookie with a primitive type in its value failed silently.

It's still unclear to me why the javascript cookie debug technique failed.

TomL
  • 759
  • 8
  • 20