美文网首页
IOS--向后台传cookie

IOS--向后台传cookie

作者: 丶大明 | 来源:发表于2016-11-03 11:44 被阅读46次


    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

          本文链接:https://www.haomeiwen.com/subject/okkekttx.html