如何设置 Accept 和 Accept-Language 标头字段?
我可以设置 Request.Content-Type = ... , Request.Content-Length = ...
如何设置 Accept 和 Accept-Language?
我想上传文件(RFC 1867)并且需要创建如下请求:
POST /test-upload.php.xml HTTP/1.1 Host: example.com User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: tr-tr,tr;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-9,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Content-Type: multipart/form-data; boundary=---------------------------21724139663430 Content-Length: 56048
I can set Request.Content-Type = ... , Request.Content-Length = ...
How to set Accept and Accept-Language?
I want to upload a file (RFC 1867) and need to create a request like this:
POST /test-upload.php.xml HTTP/1.1 Host: example.com User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: tr-tr,tr;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-9,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Content-Type: multipart/form-data; boundary=---------------------------21724139663430 Content-Length: 56048
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
查看接受属性:
这篇 MSDN 文章展示了如何向您的请求添加自定义标头:
Take a look at Accept property:
This MSDN article shows how to add custom headers to your request:
当你想设置Accept类型和内容类型时,只需将webrequest强制转换为HttpwebRequest
When you want to set the Accept type and content type, just cast the webrequest to HttpwebRequest
您需要确保将请求类型转换为 (HttpWebRequest),其中接受标头属性可用。
在旧的 WebRequest 类中,Accept 标头不可访问。
You need to be sure that you type cast the request to (HttpWebRequest), where the accept header property is available.
In the old WebRequest class, the Accept header is not accessible.
在多次尝试使用标头后,我必须确认
myWebHeaderCollection.Add("foo","bar"); 解决方案完美运行。
如果你想设置语言。
但不设置值。鉴于第一个可行,这似乎是一个合乎逻辑的结论。
I have to confirm after several annoying attempts to use the headers that the
myWebHeaderCollection.Add("foo","bar");
solution works perfectly.if you want to set the Language.
Does not set the values however. Which may seem like a logical conclusion given the first one works.
如果您使用 HttpRequestMessage,请设置标头使用 Headers.Add 方法。在你的情况下:
If you are using HttpRequestMessage, set the header using Headers.Add method. In your case :
在我有幸维护 15 年前的 vb.NET 3.5 代码的情况下,这个解决方法对我来说是成功的:
In a case where I have the pleasure of maintaining 15 year old vb.NET 3.5 code, this workaround was successful for me: