gpt4 book ai didi

c# - 如何设置 Accept 和 Accept-Language header 字段?

转载 作者:IT王子 更新时间:2023-10-29 04:29:50 28 4
gpt4 key购买 nike

我可以设置 Request.Content-Type = ... , Request.Content-Length = ...

如何设置Accept和Accept-Language?

我想上传一个文件 (RFC 1867) 并且需要像这样创建一个请求:

POST /test-upload.php.xml HTTP/1.1Host: example.comUser-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: tr-tr,tr;q=0.8,en-us;q=0.5,en;q=0.3Accept-Encoding: gzip, deflateAccept-Charset: ISO-8859-9,utf-8;q=0.7,*;q=0.7Keep-Alive: 115Connection: keep-aliveContent-Type: multipart/form-data; boundary=---------------------------21724139663430Content-Length: 56048

最佳答案

看看Accept property :

HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);
myHttpWebRequest.Accept="image/*";
HttpWebResponse myHttpWebResponse=
(HttpWebResponse)myHttpWebRequest.GetResponse();

This MSDN article显示如何向您的请求添加自定义 header :

//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");

关于c# - 如何设置 Accept 和 Accept-Language header 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6224454/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com