开发者

UIWebview returns error and adds m. to request URL

开发者 https://www.devze.com 2023-03-10 11:08 出处:网络
I´m trying to load a URL to a webview. Let´s say the url is: http://www.somepage.com/ But for some reason when I load the url in the webview, it adds a m. (URL looks like this: http://m.somepage.

I´m trying to load a URL to a webview.

Let´s say the url is: http://www.somepage.com/

But for some reason when I load the url in the webview, it adds a m. (URL looks like this: http://m.somepage.com) , it seems like it´s trying to add a mobile version of the website. There isn´t a mobile version of the website, so it´s trying to load a url that doesn´t exist.

In the shouldStartLoadWithRequest delegate method for the webview, it returns the correct URL. In th开发者_JS百科e didFailWithError method I can an error saying: Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo=0x5a7c670 {NSErrorFailingURLStringKey=http://m.somepage.com

Any idea how I can fix this? Can I replace the m. with www in some way?


This is most certainly an issue with the webserver. It is redirecting your requests to a domain that does not exist. If you have access to the webserver's configuration you will need to fix this there.

If you don't have access to the webserver, your only chance at avoiding this particular issue is to send a different User-Agent string so that the webserver no longer thinks you are viewing the page from a mobile device. However, there doesn't seem to be an easy way to do this on a site-by-site basis.

Relevant Stack Overflow Question:
Change User Agent in UIWebView (iPhone SDK)


I am using the UIWebView without any issues. Can you check whether the site you are accessing has code that redirects to a mobile version?

0

精彩评论

暂无评论...
验证码 换一张
取 消