2

I'm building a windows form using a web browser. I have a URL and I want the web browser to display the mobile site. For example:

If I type: www.facebook.com, I want the web browser to navigate to: m.facebook.com. How do I pretend to be a mobile phone? I don't know what I need to do to solve my problem. I'm using Visual Studio 2012 - winform - c#.

I tried this:

WebClient client = new WebClient();
client.Headers["User-Agent"] = "myUserAgentString";
hichris123
  • 10,145
  • 15
  • 56
  • 70
user3461486
  • 261
  • 1
  • 2
  • 7
  • Okay. So you tried that. What happened? Is `"myUserAgentString"` the actual value you used? What other user agent strings have you tried – mason Mar 25 '14 at 20:35

4 Answers4

4

I know this is about a year old, but this is an easy thing to do:

First you need the user agent string and it needs to be string formatted. This is how I do it below

wbMobile.Navigate(new Uri("http://m.bing.com/", UriKind.RelativeOrAbsolute), string.Empty, null, string.Format("User-Agent: {0}", "Opera/9.80 (J2ME/MIDP; Opera Mini/9 (Compatible; MSIE:9.0; iPhone; BlackBerry9700; AppleWebKit/24.746; U; en) Presto/2.5.25 Version/10.54"));

This will navigate to the webpage using a mobile user agent string and allow you to view mobile websites on the fly in the webbrowser control

0

I used something like this: (JavaScript)

<script>
if (document.location.search.indexOf('skipmobile') >= 0) {
    document.cookie = 'skipmobile=1';
}
else if ((document.location.hostname.match(/\.mobi$/) || screen.width < 799)
&& document.cookie.indexOf('skipmobile') == -1)
{
    document.location = 'm/';
}
</script>

In other words, if screen display is under 799px, redirect user to the mobile version, which was mysite.com/m/

obey
  • 796
  • 7
  • 16
  • i want to pretend to be a mobile phone and not to check if a site is for mobile phone.... and i don't use javascript in my code... – user3461486 Mar 26 '14 at 21:38
0

Here is the user agent string for iphone ios5

Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3

From: What is the iOS 5.0 user agent string?

Community
  • 1
  • 1
major-mann
  • 2,602
  • 22
  • 37
  • can you be more detailed? can you write exactlly what i need to write? – user3461486 Mar 26 '14 at 21:37
  • @user3461486 client.Headers["User-Agent"] = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3" – major-mann Mar 27 '14 at 07:59
  • still don't work. how do i combined what you gave me with the http request from the site (for requesting the source code)? – user3461486 Mar 28 '14 at 16:29
  • Use something like wireshark to check the full set of headers a mobile device sends. Send the same, and you should receive a mobile version of the site. – major-mann Mar 29 '14 at 23:13
0

You can get the code you need from detectmobilebrowsers.com

You can the use F12 developer tools in IE 10+ to emulate mobile browsers.

bnieland
  • 6,047
  • 4
  • 40
  • 66