当我向请求添加cookie时,iOS UIWebView有一个空白页面

时间:2017-09-19 15:06:26

标签: ios uiwebview

当我向UIWebView请求添加cookies标头时,我得到一个空白页面。当请求中没有cookie头时,它会很好地加载页面。当我使用curl命令尝试此请求时,它会很好地加载页面。

curl --header "Cookie: id=0036100001CWQLFAA5; sn=209caec4cc6d3916186218685c4bea9b1ad4084b; visitor_id290562=124369749; visitor_id290562-hash=262c38ffdae6a7a373cb06ea327cb6bca047b78434f6e15b62f2859c0eab2cd0897a220a4640848783fd8b34008c041eea5adc46" https://ecommerce.thebullbag.com/my-account > Desktop/1.html

这是我的Swift代码:

let url = URL(string: WebSiteUrl + "/my-account")!
            let webController = TOWebViewController(url: url)!
            webController.urlRequest.addValue("Cookie", forHTTPHeaderField: "id=0036100001CWQLFAA5; sn=209caec4cc6d3916186218685c4bea9b1ad4084b; visitor_id290562=124369749; visitor_id290562-hash=" +
                    "262c38ffdae6a7a373cb06ea327cb6bca047b78434f6e15b62f2859c0eab2cd0897a220a4640848783fd8b34008c041eea5adc46")
            let navigationController = UINavigationController(rootViewController: webController)
            self.present(navigationController, animated: true)

当我删除webController.urlRequest.addValue页面时,该页面已正确加载。

我将所有内容添加到Info.plist

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>ecommerce.thebullbag.com</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSIncludesSubdomains</key>
                <true/>
                <!--Include to allow HTTP requests-->
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <!--Include to specify minimum TLS version-->
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
            </dict>
        </dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
    </dict>

1 个答案:

答案 0 :(得分:0)

这是一个错字:

webController.urlRequest.addValue("id=0036100001CWQLFAA5; sn=209caec4cc6d3916186218685c4bea9b1ad4084b; visitor_id290562=124369749; visitor_id290562-hash=" +
                    "262c38ffdae6a7a373cb06ea327cb6bca047b78434f6e15b62f2859c0eab2cd0897a220a4640848783fd8b34008c041eea5adc46",
                    forHTTPHeaderField: "Cookie")