本文介绍了如何设置接受并Accept-Language头字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以设置Request.Content类型= ...,Request.Content长度= ...
如何设置接受并接受语言
我要上传的文件(RFC 1867),并需要建立这样的请求:
POST /test-upload.php.xml HTTP / 1.1
主机:example.com
的User-Agent:Mozilla的/ 5.0(Windows NT的5.2; WOW64; RV:2.0.1)壁虎/ 20100101火狐/ 4.0.1
接受:text / html的,是application / xhtml + xml的,应用/ XML; q = 0.9 * / *; q = 0.8
接受语言:TR-TR ,TR; q = 0.8,EN-US; q = 0.5,连接; q = 0.3
接受编码:gzip,紧缩
接收字符集:ISO-8859-9,UTF-8,q = 0.7 * q = 0.7
保持活动:115
连接:保持活动
内容类型:多重/ form-data的;边界= --------------------------- 21724139663430
的Content-Length:56048
解决方案
看看的:
HttpWebRequest的myHttpWebRequest =(HttpWebRequest的)WebRequest.Create(myUri);
myHttpWebRequest.Accept =图像/ *;
HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myHttpWebRequest.GetResponse();
的展示了如何自定义页眉添加到您的请求:
//获取与请求相关联的标题。
WebHeaderCollection myWebHeaderCollection = myHttpWebRequest.Headers;
//添加Accept-Language头(丹麦)的请求。
myWebHeaderCollection.Add(接受语言:DA);
//在接受-语言特点接头,包括英语。
myWebHeaderCollection.Add(接受语言,恩; Q = 0.8);
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
解决方案
Take a look at Accept property:
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);
myHttpWebRequest.Accept="image/*";
HttpWebResponse myHttpWebResponse=
(HttpWebResponse)myHttpWebRequest.GetResponse();
This MSDN article shows how to add custom headers to your request:
//Get the headers associated with the request.
WebHeaderCollection myWebHeaderCollection = myHttpWebRequest.Headers;
//Add the Accept-Language header (for Danish) in the request.
myWebHeaderCollection.Add("Accept-Language:da");
//Include English in the Accept-Langauge header.
myWebHeaderCollection.Add("Accept-Language","en;q=0.8");
这篇关于如何设置接受并Accept-Language头字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!