nshttpcookie

使用Swift读取Cookie内容

微笑、不失礼 提交于 2019-12-07 00:10:52
前言 一个http请求中,我们经常会涉及到Get请求的URL Param,POST请求的HTTP Body,Response Json,这些都是一个标准REST API标配的元素。 在一些安全验证的API中,通常会涉及到Cookie。当用户成功登陆后,服务器会在Response Header中写入一个Set-Cookie字段,用来标识用户已经登陆(授权)成功,客户端浏览器接收后会把这个Cookie字段保存在客户端本地。当客户端再次请求API时,就会在Request Header中带上这个Cookie值,告诉服务器:嗨,我已经授权过咯,我的cookie值是xxx,我现在要读取一些信息,请放行~ IOS中的网络请求 一个完整的网络请求,需要先确定Request URL,带上参数,然后发送Request,然后接收Response,处理Response Data。 在IOS中,分别对应如下: //Request URL NSURL //一个完整的Request对象 NSURLRequest //发送请求连接的主要操作者 NSURLConnection //包含返回数据的Response NSURLResponse 下面是一个简单的GET请求代码: let request = NSURLRequest(URL: NSURL(string: "http://devonios.com")!)

Creating a non-tracking in-app web browser

南楼画角 提交于 2019-12-03 07:09:41
I am trying to create a webview (as an exercise) that does not track or store any browsing history locally. I have made it so that when the webview is closed, it calls the following [[NSURLSession sharedSession]resetWithCompletionHandler:^{}]; but I am finding that things like google search history persists some how between sessions. I have also tried clearing cookies separately through NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (NSHTTPCookie *cookie in [storage cookies]) { [storage deleteCookie:cookie]; } [[NSUserDefaults standardUserDefaults]

Shared instance of NSHTTPCookieStorage does not persist cookies

∥☆過路亽.° 提交于 2019-12-03 06:51:34
问题 I'm developing an application where the server hands me a cookie to identify the user. My successive requests need to have that cookie to have the response that the user expects. What I can't understand is how and when the shared instance of NSHTTPCookieStorage loses its cookies. The first solution I used is to archive and save the cookies from my server to user defaults on application terminations then clear existing ones from my server on application launch and reset the ones I stored.

Clear iPhone simulator cookies

寵の児 提交于 2019-12-03 03:33:23
I have an app that makes request to a REST service. Authentication is done using cookies. This already works. What I have problems with is to test the case when the cookie is no longer valid and my code has to reauthenticate. To test this I have to wait until the cookie is invalid, which could take some time. To accelerate this I figured that if I delete the cookie it would have the same effect. How to delete all cookies of an app on the iPhone simulator? I already tried the following: Deleting <app-dir>/Library/Cookies/Cookies.binarycookies doesn't work. It seems that my cookies are never

Shared instance of NSHTTPCookieStorage does not persist cookies

不羁的心 提交于 2019-12-02 19:26:07
I'm developing an application where the server hands me a cookie to identify the user. My successive requests need to have that cookie to have the response that the user expects. What I can't understand is how and when the shared instance of NSHTTPCookieStorage loses its cookies. The first solution I used is to archive and save the cookies from my server to user defaults on application terminations then clear existing ones from my server on application launch and reset the ones I stored. Through the developing process I didn't encounter problems as the sessions for debugging are very short and

WKWebView did't give all cookies in navigationResponse

為{幸葍}努か 提交于 2019-12-01 19:41:02
问题 I am trying to replace my working UIWebView project with WkWebView. I've seen many posts but i did't get any good solution for getting all cookies from WKWebView. I've also tried this evaluateJavaScript:@"document.cookie;" but it gives me this () . I also checked this post and also tried this solution as i understood but it also did't works. guard let cookies = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies else { return } Above method is only works with UIWebView because WKWebView

Set Cookie for UIWebView requests

…衆ロ難τιáo~ 提交于 2019-11-30 21:42:18
I want to embed an UIWebView into my MonoTouch application for an area that is not yet implemented natively. In order to authenticate with the website I want to set a cookie containing a key for the current session. I tried creating a NSDictionary with the properties for the Cookie and then create a new NSHttpCookie and add it to the NSHttpCookieStorage.SharedStorage . Sadly the cookie seems to be empty and not used for the request. An example of how to build be cookie with properties and a comment on whether or not this is the simplest way to do this would be greatly appreciated. Whenever I

Separate cookie storage for two (UIWebView or WKWebView)

空扰寡人 提交于 2019-11-30 03:35:54
问题 I want to login many accounts of same site in different webView . For example i have Tab Bar Controller that contains three view controllers and each view controllers contain webView . And for example i embed stackoverflow url for webView in every class. How user can login to different accounts at the same time using these three webView ? I've tried this but i can just login one user at a time. I have found that i need to create separate cookie for every UIWebView , but mostly answers are in

AFNetworking Persisting Cookies Automatically

限于喜欢 提交于 2019-11-30 02:24:37
In: This Question it is said AFNetworking takes care of cookies automatically in the background, but in a Previous question I asked, I was having trouble keeping the session on the server that was made in php when I logged in. Once I closed(stop debugging in Xcode) the app and went back in the session was gone. The answer was to persist cookies like so to fix the problem: NSData *cookiesData = [[NSUserDefaults standardUserDefaults] objectForKey:@"User"]; if ([cookiesData length] > 0) { for (NSHTTPCookie *cookie in [NSKeyedUnarchiver cookiesData]) { [[NSHTTPCookieStorage sharedHTTPCookieStorage

AFNetworking Persisting Cookies Automatically

时光总嘲笑我的痴心妄想 提交于 2019-11-28 23:15:39
问题 In: This Question it is said AFNetworking takes care of cookies automatically in the background, but in a Previous question I asked, I was having trouble keeping the session on the server that was made in php when I logged in. Once I closed(stop debugging in Xcode) the app and went back in the session was gone. The answer was to persist cookies like so to fix the problem: NSData *cookiesData = [[NSUserDefaults standardUserDefaults] objectForKey:@"User"]; if ([cookiesData length] > 0) { for