<legend id='0Eh1y'><style id='0Eh1y'><dir id='0Eh1y'><q id='0Eh1y'></q></dir></style></legend>
    <bdo id='0Eh1y'></bdo><ul id='0Eh1y'></ul>
  • <small id='0Eh1y'></small><noframes id='0Eh1y'>

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

        WebClient 设置标头

        时间:2023-08-26
      1. <tfoot id='i9co4'></tfoot>
      2. <small id='i9co4'></small><noframes id='i9co4'>

        • <i id='i9co4'><tr id='i9co4'><dt id='i9co4'><q id='i9co4'><span id='i9co4'><b id='i9co4'><form id='i9co4'><ins id='i9co4'></ins><ul id='i9co4'></ul><sub id='i9co4'></sub></form><legend id='i9co4'></legend><bdo id='i9co4'><pre id='i9co4'><center id='i9co4'></center></pre></bdo></b><th id='i9co4'></th></span></q></dt></tr></i><div id='i9co4'><tfoot id='i9co4'></tfoot><dl id='i9co4'><fieldset id='i9co4'></fieldset></dl></div>
              <tbody id='i9co4'></tbody>

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

                1. <legend id='i9co4'><style id='i9co4'><dir id='i9co4'><q id='i9co4'></q></dir></style></legend>
                  本文介绍了WebClient 设置标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何在 webClient 类中设置标题?我试过了:

                  How I can set a header in the webClient class? I tried:

                  client.Headers["Content-Type"] = "image/jpeg";
                  

                  抛出 WebException

                  我的代码:

                  WebClient client = new WebClient();
                  client.Headers.Set("Content-Type", "image/png");
                  client.Headers.Set("Content-Length", length);
                  client.Headers.Add("Slug", name);
                  NameValueCollection nvc = new NameValueCollection();
                  nvc.Add("file", FileContents);
                  
                  Byte[] data = client.UploadValues(url, nvc);
                  string res = Encoding.ASCII.GetString(data);
                  Response.Write(res);
                  

                  推荐答案

                  如果header已经存在:

                  If the header already exists:

                  client.Headers.Set("Content-Type", "image/jpeg");
                  

                  如果是新标题:

                  client.Headers.Add("Content-Type", "image/jpeg");
                  

                  此外,您可能会遇到错误,因为您尝试设置标题太晚了.发布您的例外情况,以便我们通知您.

                  Also, there is a chance that you are getting an error because you are trying to set the headers too late. Post your exception so we can let you know.

                  更新

                  看起来对 WebClient 类的Content-Type"标头有一些奇怪的限制.考虑使用 client.Download 方法(DownloadData、DownloadFile 等)

                  看看在 webclient 上使用UploadFile"方法是否有效,而不是手动进行.它返回响应体字节[].

                  See if using the "UploadFile" method on webclient works rather than doing it manually. It returns the respose body byte[].

                  如果您仍然遇到 WebClient 问题,请尝试使用普通的旧 HttpRequest/HttpWebRequest.

                  If you continue to have issues with the WebClient, try justing using a plain old HttpRequest/HttpWebRequest.

                  这篇关于WebClient 设置标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:正则表达式解析 C/C++ 函数声明 下一篇:如何在 RabbitMQ 中设置重试次数?

                  相关文章

                  最新文章

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

                  <tfoot id='llIuq'></tfoot>
                    <bdo id='llIuq'></bdo><ul id='llIuq'></ul>

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

                    <legend id='llIuq'><style id='llIuq'><dir id='llIuq'><q id='llIuq'></q></dir></style></legend>