<legend id='dfYwE'><style id='dfYwE'><dir id='dfYwE'><q id='dfYwE'></q></dir></style></legend>
  • <small id='dfYwE'></small><noframes id='dfYwE'>

      <bdo id='dfYwE'></bdo><ul id='dfYwE'></ul>

    1. <tfoot id='dfYwE'></tfoot>
    2. <i id='dfYwE'><tr id='dfYwE'><dt id='dfYwE'><q id='dfYwE'><span id='dfYwE'><b id='dfYwE'><form id='dfYwE'><ins id='dfYwE'></ins><ul id='dfYwE'></ul><sub id='dfYwE'></sub></form><legend id='dfYwE'></legend><bdo id='dfYwE'><pre id='dfYwE'><center id='dfYwE'></center></pre></bdo></b><th id='dfYwE'></th></span></q></dt></tr></i><div id='dfYwE'><tfoot id='dfYwE'></tfoot><dl id='dfYwE'><fieldset id='dfYwE'></fieldset></dl></div>

        使用 HttpWebRequest 添加自定义标头

        时间:2023-10-25
        <legend id='cgYsE'><style id='cgYsE'><dir id='cgYsE'><q id='cgYsE'></q></dir></style></legend>
        <i id='cgYsE'><tr id='cgYsE'><dt id='cgYsE'><q id='cgYsE'><span id='cgYsE'><b id='cgYsE'><form id='cgYsE'><ins id='cgYsE'></ins><ul id='cgYsE'></ul><sub id='cgYsE'></sub></form><legend id='cgYsE'></legend><bdo id='cgYsE'><pre id='cgYsE'><center id='cgYsE'></center></pre></bdo></b><th id='cgYsE'></th></span></q></dt></tr></i><div id='cgYsE'><tfoot id='cgYsE'></tfoot><dl id='cgYsE'><fieldset id='cgYsE'></fieldset></dl></div>

        • <small id='cgYsE'></small><noframes id='cgYsE'>

            <tfoot id='cgYsE'></tfoot>

                <tbody id='cgYsE'></tbody>
              • <bdo id='cgYsE'></bdo><ul id='cgYsE'></ul>
                  本文介绍了使用 HttpWebRequest 添加自定义标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我不确定这些突出显示的值是什么类型的标头,但是我应该如何使用 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 添加自定义标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 ASP.net C# 中伪造浏览器请求 下一篇:Response.Redirect 剥离 Header Referrer - 可以将其添加回来吗?

                  相关文章

                  • <bdo id='G49YL'></bdo><ul id='G49YL'></ul>

                  <small id='G49YL'></small><noframes id='G49YL'>

                • <i id='G49YL'><tr id='G49YL'><dt id='G49YL'><q id='G49YL'><span id='G49YL'><b id='G49YL'><form id='G49YL'><ins id='G49YL'></ins><ul id='G49YL'></ul><sub id='G49YL'></sub></form><legend id='G49YL'></legend><bdo id='G49YL'><pre id='G49YL'><center id='G49YL'></center></pre></bdo></b><th id='G49YL'></th></span></q></dt></tr></i><div id='G49YL'><tfoot id='G49YL'></tfoot><dl id='G49YL'><fieldset id='G49YL'></fieldset></dl></div>
                  1. <legend id='G49YL'><style id='G49YL'><dir id='G49YL'><q id='G49YL'></q></dir></style></legend>
                  2. <tfoot id='G49YL'></tfoot>