简体   繁体   English

如何使用uiwebview打开php网页?

[英]How can I open a php webpage with uiwebview?

I'm trying to open/display the rssfeed http://www.golfweekly.nl/rss.php in a uiwebview. 我正在尝试在uiwebview中打开/显示rssfeed http://www.golfweekly.nl/rss.php But the screen stays blank. 但是屏幕保持空白。 Opening http://www.google.com will just show the google content. 打开http://www.google.com只会显示Google内容。

This is how my WebView.m file is looking: 这是我的WebView.m文件的外观:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *strWebPage = @"http://www.golfweekly.nl/rss.php";
    NSURL *url = [NSURL URLWithString:strWebPage];
    NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];

    [webViewBuienRadar loadRequest:requestURL];
    [strWebPage release];   

}

After some very usefull tip/response it works with the following code : 经过一些非常有用的提示/响应后,它可以使用以下代码:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. //加载视图后,通常通过笔尖实现viewDidLoad进行其他设置。

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString * userAgent = @"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+(KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3";
    NSString * urlString = @"http://reader.mac.com/mobile/v1/http%3A%2F%2Fwww.golfweekly.nl%2Frss.php";
    NSURL *URL = [NSURL URLWithString:urlString];
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:URL];
    [req setValue:userAgent forHTTPHeaderField:@"User-Agent"];
    NSURLResponse* response = nil;
    NSError* error = nil;
    NSData* data = [NSURLConnection sendSynchronousRequest:req
                                         returningResponse:&response
                                                     error:&error];
    [webViewBuienRadar loadData:data MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:URL];
}

Your URL above serves an RSS and not a HTML page. 您上面的网址提供的是RSS,而不是HTML页面。 Main desktop browsers like firefox, ie, etc. have a feature to parse the RSS and render it to a user-readable form. 主要桌面浏览器(例如firefox等)具有解析RSS并将其呈现为用户可读形式的功能。 UIWebView does not have this feature as far as I know thus it can not load the page. 据我所知,UIWebView没有此功能,因此无法加载页面。 You will need to parse the RSS file yourself and generate a HTML page (or even table view contents, etc) based on it. 您将需要自己解析RSS文件并基于该文件生成HTML页面(甚至是表格​​视图内容等)。

Please, refer to that post where you can find a suggestion allowing you to parse the incoming rss feed as the UIWebview wouldn't not display it. 请参考UIWebview 文章 ,您可以在其中找到建议,因为UIWebview不会显示它,所以您可以解析传入的rss feed。

Another nice solution there allows you to change your User Agent. 另一个不错的解决方案是让您更改用户代理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM