更改用户代理WebBrowser对象C# [英] Change User Agent WebBrowser Object C#

查看:492
本文介绍了更改用户代理WebBrowser对象C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多含有相同主题这一个话题,但是这些话题非能帮助我与我的问题。

I know there are a lot of topics containing the same subject as this one, but non of those topic could help me with my problem.

我在C#中制作一个简单的iPhone的网页浏览器。它应该做的唯一的事情,是演戏就像是一个iPhone。当您更改用户代理字符串这是可能的。

I'm making a simple iPhone Webbrowser in C#. The only thing it should do, is acting like it's an iPhone. This is possible when you change the User Agent String.

我试图在WebBrowser.Navigate事件,在第4个参数就可以把含有用户代理字符串的标题。但它的工作只是一个时间,你点击东西它改变了用户字符串为默认web浏览器之后。因此,这不是一个可用的方法给我。

I tried in in the WebBrowser.Navigate event, in the 4th argument you can put a header containing a User Agent String. But it's working just one time, after you click something in the WebBrowser it changes the user string to default. So this is not a useable method for me.

然后我尝试了ExtendedWebBrowser控制,我在互联网上找到。当你忧色该控件可以设置在属性窗口的用户代理,但这并不适合我在所有的工作。

Then i tried an ExtendedWebBrowser control that i found on the internet. When you youse that control you can set the User Agent in the properties windows, but this doesn't work at all for me.

所以,最后我试图用urlmon.dll中设置用户代理,但everywere当他们谈论它,他们谈论重新启动的过程。我无法找到任何与该DLL的工作,所以我不能让过程是工作的。而如果它会工作,它不是每次重新启动它,我想使用的应用程序的可能性。

So at last i tried to use the urlmon.dll to set the User Agent, but everywere when they talk about it, they talk about restarting the process. I can't find any process working with that DLL so i can't get is to work either. And if it would work, it's not a possibility to restart it everytime i want to use the application.

有人可以帮助我得到一个回答我的问题,我与现在每天挣扎?

Can someone help me to get a answer to my question, i'm struggling with for a day now?

感谢你在前进的人!

推荐答案

下面是你如何改变用户代理

Here's how you change the UserAgent

[DllImport("urlmon.dll", CharSet = CharSet.Ansi)]
private static extern int UrlMkSetSessionOption(int dwOption, 
string pBuffer, int dwBufferLength, int dwReserved);

const int URLMON_OPTION_USERAGENT = 0x10000001;

string ua = "YourUserAgentString";

UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, ua, ua.Length, 0);

这篇关于更改用户代理WebBrowser对象C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆