[英]How do I set the HttpRequestHeader for a HttpWebRequest?
I'm trying to set the HttpRequestHeader for a HttpWebRequest like so: 我正在尝试为HttpWebRequest设置HttpRequestHeader,如下所示:
new HttpWebRequest().Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0");
But I get an exception: System.ArgumentException: This header must be modified using the appropriate property
. 但是我得到一个异常: System.ArgumentException: This header must be modified using the appropriate property
。
How should I be setting the header? 我该如何设置标题?
UserAgent
is a property. UserAgent
是一个属性。 So set it like this: 所以设置如下:
HttpWebRequest request = new HttpWebRequest();
request.UserAgent = "Mozilla/4.0";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.