问题描述
我不确定这些突出显示的值是什么类型的标头,但是我应该如何使用 HttpWebRequest 添加它们?
I am not really sure what type of headers these highlighted values are, but how should I add them using HttpWebRequest?
突出显示的部分是否被视为 http 请求的主体或标头数据?也就是说,哪种方式是正确的?
Is the highlighted part considered body of the http request or header data? In other words, which way is correct?
这是我目前使用的代码:
Here is the code I am currently using:
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("/securecontrol/reset/passwordreset");
request.Headers.Add("Authorization", "Basic asdadsasdas8586");
request.ContentType = "application/x-www-form-urlencoded";
request.Host = "www.xxxxxxxxxx.com";
request.Method = "POST";
request.Proxy = null;
request.Headers.Add("&command=requestnewpassword");
request.Headers.Add("&application=netconnect");
但是我应该改用以下来构建上面的 Http 请求吗?
But should I use the following instead to build the Http Request above?
string reqString = "&command=requestnewpassword&application=netconnect";
byte[] requestData = Encoding.UTF8.GetBytes(reqString);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("/securecontrol/reset/passwordreset");
request.Headers.Add("Authorization", "Basic ashAHasd87asdHasdas");
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = requestData.Length;
request.Proxy = null;
request.Host = "www.xxxxxxxxxx.com";
request.Method = "POST";
using (Stream st = request.GetRequestStream())
st.Write(requestData, 0, requestData.Length);
推荐答案
恕我直言,它被视为格式错误的标头数据.
IMHO it is considered as malformed header data.
您实际上希望将这些名称值对作为请求内容发送(这是 POST 的工作方式)而不是作为标头.
You actually want to send those name value pairs as the request content (this is the way POST works) and not as headers.
第二种方法是正确的.
这篇关于使用 HttpWebRequest 添加自定义标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)