Tag: Cookie

如何从Web服务器获取cookie并将其保存在iOS应用程序中?

我想从http://mycompany.com/page1…http://mycompany.com/page2获取JSON …在web服务器端,它需要初始loginhttp://mycompany.com / login ,然后为用户维护一个cookie。 我怎么得到这个NSURLConnection行为,而不必每次都要求login? 这是使用NSURLCredential存储的非工作代码。 我是否需要在login时从web服务获取cookie,然后将其与以后的请求一起发送? 我一直在努力,所以你可以澄清一下你的答案。 – (IBAction)getJSON:(id)sender { NSURLCredential *credential = [NSURLCredential credentialWithUser:@"user" password:@"pass" persistence:NSURLCredentialPersistenceForSession]; NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:@"myCompany.com" port:0 protocol:@"http" realm:nil authenticationMethod:nil]; [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:credential forProtectionSpace:protectionSpace]; //////////GET JSON////////////// NSError *error; NSURL *url = [NSURL URLWithString:@"http://mycompany.com.jsonpage1"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; } //I am NOT […]

在iOS Safari浏览器会话之间不保存Cookie

我有一个MVC 4网站,用户可以login,我用他们的会话信息保存一个cookie,所以他们不必再次login。 public void SetCookie(HttpCookie cookie) { HttpContext.Current.Response.Cookies.Set(cookie); } 这在桌面设备上工作,但是当我在iOS上运行这个,它不能100%的时间工作。 如果我在移动浏览器(Chrome或Safari)中至less保留1个页面,并导航回我的网站,我的会话cookie被find,我不必login。 但是,如果我closures该浏览器的所有窗口,那么下一次导航回我的网站时,会话cookie不会被发现。 我在我的Cookie上设置了1年的期限/到期时间,因此不会过期。 到目前为止我发现的唯一的事情是,这是.NET 4.0中的一个错误,在.NET 4.5中已经修复。 我相信我已经在运行.NET 4.5,通过查看我的* .csproj和TargetFrameworkVersion元素: <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProductVersion> </ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{xxxxxxxxxxxxxxxxxx}</ProjectGuid> <ProjectTypeGuids>{xxxxxxxx};{xxxxxxxxxxxxx};{xxxxxxxxxxxxxxxx}</ProjectTypeGuids> <OutputType>Library</OutputType> <AppDesignerFolder>Properties</AppDesignerFolder> <RootNamespace>MyApp</RootNamespace> <AssemblyName>MyApp</AssemblyName> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <MvcBuildViews>false</MvcBuildViews> <UseIISExpress>true</UseIISExpress> <IISExpressSSLPort /> <IISExpressAnonymousAuthentication […]

在closures应用程序时,webview的cookie会发生什么变化?

我正在使用一个web应用程序,让我loginfunction像facebook app.so为了实现我需要的cookie应persistant.I只是想知道当应用程序closures时ios是否保持默认的cookie或者我需要在closures应用程序之前手动保存cookie以实现保持我loginfunction。 任何帮助将深表感谢。 谢谢

用NSURLSession设置cookie

嗨,我正在开发一个Iphone应用程序,我想在服务器响应后设置cookie,并将其用于另一个请求。 我的networking请求看起来像。 NSURLSession *session = [NSURLSession sharedSession]; [[session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response; NSLog(@"sttaus code %i", httpResp.statusCode); if (error) { [self.delegate signinWithError:error]; } else { [self.delegate signinWithJson:data]; } }] resume]; 但我不知道如何设置cookie。 我知道我必须使用NSHTTPCookieStorage但我不知道如何设置。 而且我也希望将这个cookie用于另一个请求。 有没有人知道这个? 需要帮忙。 谢谢。 看我以这种方式尝试 NSURLSession *session = [NSURLSession sharedSession]; [[session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse […]

NSURLConnection是否会自动保存从服务器发送的Cookie?

我从ioslogin到我的龙卷风后端,并发回了一个secure_cookie,我注意到,只要我validation了我设置的secure_cookie,我也可以请求其他信息。 NSURLConnection持续了多长时间,或者一旦closures了应用程序,cookie会被删除? 这在Apple文档中提到: URL加载系统自动发送适合NSURLRequest的任何存储的cookie。 除非请求指定不发送cookie。

iOS全屏Web App会丢弃Cookie?

我经历过,当你开始/退出一个保存在仪表板(全屏模式)的网页应用程序时,iOS4会删除cookies。 这是真的,有没有解决方法?

UIWebview启用cookie

我试图通过UIWebView访问需要cookie的特定URL,但由于禁用了cookie,我无法访问它。 所以我做了以下几点: 启用Cookie: NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; 创buildNSURLConnection并从响应中提取cookie: NSArray *cookies = [ NSHTTPCookie cookiesWithResponseHeaderFields: [ httpResponse allHeaderFields ] forURL:response.URL]; [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies: cookies forURL: response.URL mainDocumentURL:nil]; 但是这两者都没有帮助。 但是,如果我在safari中启动URL,则会成功加载,之后我可以在UIWebView加载相同的URL。 你能帮我这个,我怎么能启用cookie的UIWebView ? 提前致谢

Swift:如何记住进一步的http请求的cookie

我正在开发一个login应用程序。 成功的login响应返回cookie数据。 我如何使用/保存这些数据用于将来的请求? 对于初学者,我试图将其保存在NSHTTPCookieStorage 。 但是这也不起作用。 login方法(部分): let task = session.dataTaskWithRequest(request) { (data, responseData, error) -> Void in if let response = responseData as? NSHTTPURLResponse { statusCode = response.statusCode print("Response code: \(statusCode)") } var json: NSDictionary? do { json = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves) as? NSDictionary } catch { print(error) err = error } if(statusCode […]

WKWebView持久存储Cookie

我在我的本地iPhone应用程序,允许login/注册的网站上使用WKWebView,并将会话信息存储在Cookie中。 我想弄清楚如何持久存储cookie信息,所以当应用程序重新启动时,用户仍然可以访问他们的Web会话。 我在应用程序中有2个WKWebViews,他们共享一个WKProcessPool。 我从一个共享进程池开始: WKProcessPool *processPool = [[WKProcessPool alloc] init]; 然后对于每个WKWebView: WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init]; theConfiguration.processPool = processPool; self.webView = [[WKWebView alloc] initWithFrame:frame configuration:theConfiguration]; 当我使用第一个WKWebViewlogin时,稍后再传递给第二个WKWebView,这个会话被保留,所以cookies被成功共享。 但是,当我重新启动应用程序时,会创build一个新的进程池,会话信息被销毁。 有什么办法让会话信息通过应用程序重新启动持续?

如何在Swift中使用UIWebViewpipe理cookie

怎么样有一个话题,人们可以很容易地看到如何使用新的Swift语言来pipe理web浏览器中的cookie? 如果你在互联网上登记,当你需要实施这个时,你不会发现任何有趣的事情。 即使是苹果的文档也很差。 有谁知道如何在Swift中处理这些过程? 这是我发现,但在Obj – C: 看存储的COOKIES NSHTTPCookie *cookie; NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [cookieJar cookies]) { NSLog(@"%@", cookie); } 删除存储的曲奇 NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (NSHTTPCookie *cookie in [storage cookies]) { [storage deleteCookie:cookie]; } [[NSUserDefaults standardUserDefaults] synchronize]; 如果我们能给一次答案,这将是很好的! 干杯!