0

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 the 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?

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
Magnus
  • 11
  • 3

2 Answers2

1

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)

Community
  • 1
  • 1
Sebastian Celis
  • 12,185
  • 6
  • 36
  • 44
  • I´ve already tried this, and it doesn´t work. I don´t have access to the webserver. I talked to them a few days ago and they said they had no plans what so ever to have a mobile website. Weird thing is, I have an older version of the app on my iPhone, and it works fine. I´m rebuilding it now, with the same code for the webview but now it doesn´t work. – Magnus Jun 02 '11 at 14:32
  • But you said that Mobile Safari is also failing in the same way. This means that there is nothing wrong with your app. Are you sure you changed the User-Agent string? Try setting it to the one used by desktop Firefox, Chrome, or Safari. – Sebastian Celis Jun 02 '11 at 14:34
0

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?

dotnetster
  • 1,601
  • 1
  • 16
  • 19
  • I know for sure they don´t. I tried to open up the correct URL in Safari browser in the simulator, and I get the same error. – Magnus Jun 02 '11 at 14:03
  • @Magnus In that case, I think you need to see whether there is a load-balancing device (F5 or similar) that is checking the user agent and trying to redirect to a different flavor of the site (even though it does not exist). – dotnetster Jun 02 '11 at 14:24