IOS--向后台传cookie


NSURL*cookieHost=[NSURL URLWithString:webStr];

// 設定 cookie

NSHTTPCookie*cookie=[NSHTTPCookie cookieWithProperties:

[NSDictionary dictionaryWithObjectsAndKeys: [cookieHost host],NSHTTPCookieDomain,[cookieHost path],NSHTTPCookiePath,@"t",NSHTTPCookieName,[USER_D objectForKey:@"TokenLH"],NSHTTPCookieValue, nil]];

// 設定 cookie 到 storage 中

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];

其中NSHTTPCookiePath 后面的@“t”就是后台提供的参数名,NSHTTPCookieName是我们自己传的值

NSHTTPCookie*cookie1=[NSHTTPCookie cookieWithProperties:

[NSDictionary dictionaryWithObjectsAndKeys: [cookieHost host],NSHTTPCookieDomain,[cookieHost path],NSHTTPCookiePath,@"g",NSHTTPCookieName,[USER_D objectForKey:@"NativeLhUUID"],NSHTTPCookieValue, nil]];

// 設定 cookie 到 storage 中

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie1];

我这边是传了两个参数--@“t”和@“g”

[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:webStr]]];


网上查找的资料,做下笔记,O(∩_∩)O哈哈~

你可能感兴趣的:(IOS--向后台传cookie)