简体   繁体   中英

c# .NET 4.5 HttpWebRequest for portable crossplatforms

I cannot change user agent of HttpWebRequest:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Headers[HttpRequestHeader.UserAgent] = "test";

Always throw exception. Someone have idea how solve this?

You need to use request.UserAgent property to set the user agent.

https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.useragent(v=vs.100).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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