【问题标题】:Whats wrong with simple html NSString?简单的 html NSString 有什么问题?
【发布时间】:2013-08-29 15:33:09
【问题描述】:

大家好,我有一个简单的 html NSString,它可以在浏览器上正常工作,但不能在 iPhone 上加载。我使用的是简单的:[self.w loadHTMLString:errorString baseURL:nil]。我错过了什么?

NSString* errorString = [NSString stringWithFormat:
        @"<html><body> <iframe src=\"http://64.183.101.142:81/pda.htm\"width=\"500\" height=\"500\"></iframe></body></html>"];

【问题讨论】:

  • HTML 看起来不完整...
  • @futureelite7 缺少什么? html 在浏览器中工作正常,所以我认为必要的部分在那里。
  • 我认为您尝试打开的 url 链接,即“64.183.101.142:81/pda.htm”需要一些身份验证。
  • @SatishAzad 是的,有用户名,但没有密码。我怎样才能修改它以使其工作?请帮帮我,我没时间了。
  • 详细看我的回答。

标签: html iphone ios uiwebview


【解决方案1】:

您需要先在 webview 上加载您的请求或 HTML,并使用具有以下协议的 UIWebViewDelegate 方法捕获此请求

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

      //capture request =>  request
       //From here you have the NSURLRequest object
  //You can extract the headers of the request to NSDictionary which will contain   //the         
//authentication cookie details, token, etc. using the following method of NSURLRequest
        //- (NSDictionary *)allHTTPHeaderFields

    }

来源Source link

【讨论】:

    【解决方案2】:

    如果需要身份验证,则需要根据请求类型修改字符串。

    如果它是一个 get 它会有一个“?”在和参数是这样的: http://xx.xx.xx.xx:81/pda.htm?user="userX"&passwd="something" 如果它是一个 post 方法,您将在您的请求正文中传递您的数据。 [NSURLRequest setHTTPBody:];

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      • 1970-01-01
      • 2011-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多