<tfoot id='Z97Hv'></tfoot>

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

        在嵌入式 UIWebView 中指定 HTTP 引用

        时间:2023-06-11

      1. <tfoot id='G4h0O'></tfoot>

              <tbody id='G4h0O'></tbody>

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

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

            • <i id='G4h0O'><tr id='G4h0O'><dt id='G4h0O'><q id='G4h0O'><span id='G4h0O'><b id='G4h0O'><form id='G4h0O'><ins id='G4h0O'></ins><ul id='G4h0O'></ul><sub id='G4h0O'></sub></form><legend id='G4h0O'></legend><bdo id='G4h0O'><pre id='G4h0O'><center id='G4h0O'></center></pre></bdo></b><th id='G4h0O'></th></span></q></dt></tr></i><div id='G4h0O'><tfoot id='G4h0O'></tfoot><dl id='G4h0O'><fieldset id='G4h0O'></fieldset></dl></div>
                <bdo id='G4h0O'></bdo><ul id='G4h0O'></ul>
                • 本文介绍了在嵌入式 UIWebView 中指定 HTTP 引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我允许用户在嵌入式 UIWebView 中打开外部页面.我可以设置与该请求一起发送的referer 标头吗?我希望我的应用在用户打开这些外部页面时获得信誉".

                  In my app, I allow the user to open up an external page in an embedded UIWebView. Is it possible for me to set the referer header that's sent with that request? I'd like for my app to get the 'cred' when the user opens up these external pages.

                  推荐答案

                  设置referer 使用 - setValue:forHTTPHeaderField:

                  NSMutableURLRequest* request = ...;
                  [request setValue:@"https://myapp.com" forHTTPHeaderField: @"Referer"];
                  

                  但请注意,根据 HTTP RFC,您不应该这样做,因为您的应用无法使用 URI 进行寻址:

                  But note that according to the HTTP RFC you shouldn't, because your app is not addressable using a URI:

                  如果获取了 Request-URI,则不得发送 Referer 字段来自没有自己的 URI 的源,例如来自用户键盘.

                  The Referer field MUST NOT be sent if the Request-URI was obtained from a source that does not have its own URI, such as input from the user keyboard.

                  ...除非您使用绑定到您的应用的自定义协议 (myapp://blah.com/blah).

                  ... unless you are using a custom protocol binded to your app (myapp://blah.com/blah).

                  您可以创建一个并调用 loadRequest: 手动或拦截用户的正常请求.

                  You can create one and call loadRequest: manually or intercepting a normal request made by the user.

                  - (BOOL) webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType) navigationType 
                  {
                      NSDictionary *headers = [request allHTTPHeaderFields];
                      BOOL hasReferer = [headers objectForKey:@"Referer"]!=nil;
                      if (hasReferer) {
                          // .. is this my referer?
                          return YES;
                      } else {
                          // relaunch with a modified request
                          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];
                                  [request setHTTPMethod:@"GET"];
                                  [request setValue:@"https://whatever.com" forHTTPHeaderField: @"Referer"];
                                  [self.webView loadRequest:request];
                              });
                          });
                          return NO;
                      }
                  }
                  

                  这篇关于在嵌入式 UIWebView 中指定 HTTP 引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在android中维护会话(应用程序在服务器端保持身份验证) 下一篇:如何使用 HTTP 标头发送非英文 unicode 字符串?

                  相关文章

                  1. <legend id='iiNuU'><style id='iiNuU'><dir id='iiNuU'><q id='iiNuU'></q></dir></style></legend>

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

                      <small id='iiNuU'></small><noframes id='iiNuU'>

                    1. <tfoot id='iiNuU'></tfoot>
                        <bdo id='iiNuU'></bdo><ul id='iiNuU'></ul>