<legend id='d4oMF'><style id='d4oMF'><dir id='d4oMF'><q id='d4oMF'></q></dir></style></legend>

    <i id='d4oMF'><tr id='d4oMF'><dt id='d4oMF'><q id='d4oMF'><span id='d4oMF'><b id='d4oMF'><form id='d4oMF'><ins id='d4oMF'></ins><ul id='d4oMF'></ul><sub id='d4oMF'></sub></form><legend id='d4oMF'></legend><bdo id='d4oMF'><pre id='d4oMF'><center id='d4oMF'></center></pre></bdo></b><th id='d4oMF'></th></span></q></dt></tr></i><div id='d4oMF'><tfoot id='d4oMF'></tfoot><dl id='d4oMF'><fieldset id='d4oMF'></fieldset></dl></div>
      <tfoot id='d4oMF'></tfoot>
    1. <small id='d4oMF'></small><noframes id='d4oMF'>

      • <bdo id='d4oMF'></bdo><ul id='d4oMF'></ul>

      使用 UIWebView loadRequest 发送自定义标头

      Send custom headers with UIWebView loadRequest(使用 UIWebView loadRequest 发送自定义标头)

      • <small id='k8lB8'></small><noframes id='k8lB8'>

              <tbody id='k8lB8'></tbody>
            <tfoot id='k8lB8'></tfoot>

              <legend id='k8lB8'><style id='k8lB8'><dir id='k8lB8'><q id='k8lB8'></q></dir></style></legend>

              <i id='k8lB8'><tr id='k8lB8'><dt id='k8lB8'><q id='k8lB8'><span id='k8lB8'><b id='k8lB8'><form id='k8lB8'><ins id='k8lB8'></ins><ul id='k8lB8'></ul><sub id='k8lB8'></sub></form><legend id='k8lB8'></legend><bdo id='k8lB8'><pre id='k8lB8'><center id='k8lB8'></center></pre></bdo></b><th id='k8lB8'></th></span></q></dt></tr></i><div id='k8lB8'><tfoot id='k8lB8'></tfoot><dl id='k8lB8'><fieldset id='k8lB8'></fieldset></dl></div>
                <bdo id='k8lB8'></bdo><ul id='k8lB8'></ul>
                本文介绍了使用 UIWebView loadRequest 发送自定义标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我希望能够使用我的 UIWebView loadRequest 方法发送一些额外的标头.

                I want to be able to send some extra headers with my UIWebView loadRequest method.

                我试过了:

                NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.reliply.org/tools/requestheaders.php"]];
                [req addValue:@"hello" forHTTPHeaderField:@"aHeader"];
                
                [self.theWebView loadRequest:req];
                

                我也尝试过继承 UIWebView 并拦截 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 方法.

                I have also tried subclassing the UIWebView and intercepting the - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType method.

                在那个方法中,我有一个如下所示的代码块:

                In that method I had a block of code which looked like this:

                NSMutableURLRequest *newRequest = [request mutableCopy];
                for(NSString *key in [customHeaders allKeys]) {
                    [newRequest setValue:[customHeaders valueForKey:key] forHTTPHeaderField:key];
                }
                [self loadRequest:newRequest];
                

                但由于某种未知原因,它导致 Web 视图无法加载任何内容(空白框)并且出现错误消息 NSURLErrorCancelled (-999)(所有已知的修复程序都无法修复它我).

                But for some unknown reason it was causing the web view to not load anything (blank frame) and the error message NSURLErrorCancelled (-999) comes up (all known fixes don't fix it for me).

                所以我不知道该怎么办.如何将自定义标头与 UIWebView 请求一起发送?

                So I am at a loss as to what to do. How can I send a custom header along with a UIWebView request?

                非常感谢!

                推荐答案

                我发现这是在我的 UIWebView 请求中添加标头的方法 - 覆盖此委托方法:

                I found that this was the way to add headers to my UIWebView request - override this delegate method:

                - (BOOL) webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType) navigationType
                

                使用此代码:

                BOOL headerIsPresent = [[request allHTTPHeaderFields] objectForKey:@"my custom header"]!=nil;
                
                if(headerIsPresent) return YES;
                
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                    dispatch_async(dispatch_get_main_queue(), ^{
                        NSURL *url = [request URL];
                        NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
                
                        // set the new headers
                        for(NSString *key in [self.customHeaders allKeys]){
                            [request addValue:[self.customHeaders objectForKey:key] forHTTPHeaderField:key];
                        }
                
                        // reload the request
                        [self loadRequest:request];
                    });
                });
                return NO;
                

                这篇关于使用 UIWebView loadRequest 发送自定义标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)
                  • <bdo id='aFDj7'></bdo><ul id='aFDj7'></ul>
                    • <legend id='aFDj7'><style id='aFDj7'><dir id='aFDj7'><q id='aFDj7'></q></dir></style></legend>
                      <tfoot id='aFDj7'></tfoot>

                        1. <small id='aFDj7'></small><noframes id='aFDj7'>

                          <i id='aFDj7'><tr id='aFDj7'><dt id='aFDj7'><q id='aFDj7'><span id='aFDj7'><b id='aFDj7'><form id='aFDj7'><ins id='aFDj7'></ins><ul id='aFDj7'></ul><sub id='aFDj7'></sub></form><legend id='aFDj7'></legend><bdo id='aFDj7'><pre id='aFDj7'><center id='aFDj7'></center></pre></bdo></b><th id='aFDj7'></th></span></q></dt></tr></i><div id='aFDj7'><tfoot id='aFDj7'></tfoot><dl id='aFDj7'><fieldset id='aFDj7'></fieldset></dl></div>

                            <tbody id='aFDj7'></tbody>