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

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

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

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

      <tfoot id='mlNve'></tfoot>

      1. 使用 RestSharp 设置“Content-Type"标头

        时间:2023-10-25

          • <tfoot id='GDo85'></tfoot>
          • <small id='GDo85'></small><noframes id='GDo85'>

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

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

                  本文介绍了使用 RestSharp 设置“Content-Type"标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在为 RSS 阅读服务构建客户端.我正在使用 RestSharp 库与他们的 API 进行交互.

                  I'm building a client for an RSS reading service. I'm using the RestSharp library to interact with their API.

                  API 声明:

                  创建或更新记录时,您必须将 application/json;charset=utf-8 设置为 Content-Type 标头.

                  When creating or updating a record you must set application/json;charset=utf-8 as the Content-Type header.

                  这是我的代码的样子:

                  RestRequest request = new RestRequest("/v2/starred_entries.json", Method.POST);
                  request.AddHeader("Content-Type", "application/json; charset=utf-8");
                  request.RequestFormat = DataFormat.Json;
                  request.AddParameter("starred_entries", id);
                  
                  //Pass the request to the RestSharp client
                  Messagebox.Show(rest.ExecuteAsPost(request, "POST").Content);
                  

                  但是;服务返回错误

                  错误 415:请使用 'Content-Type: application/json;charset=utf-8' 标题

                  Error 415: Please use the 'Content-Type: application/json; charset=utf-8' header

                  为什么 RestSharp 不传递标头?

                  Why isn't RestSharp passing the header?

                  推荐答案

                  我的博客 在 RestSharp 1.02 版本之后没有经过测试.如果您针对我的解决方案的具体问题提交评论,我可以更新它.

                  The solution provided on my blog is not tested beyond version 1.02 of RestSharp. If you submit a comment on my answer with your specific issue with my solution, I can update it.

                  var client = new RestClient("http://www.example.com/where/else?key=value");
                  var request = new RestRequest();
                  
                  request.Method = Method.POST;
                  request.AddHeader("Accept", "application/json");
                  request.Parameters.Clear();
                  request.AddParameter("application/json", strJSONContent, ParameterType.RequestBody);
                  
                  var response = client.Execute(request);
                  

                  这篇关于使用 RestSharp 设置“Content-Type"标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:HttpClient 请求类似浏览器 下一篇:如何设置 httpexpires 和 cachecontrol 标头

                  相关文章

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

                  <tfoot id='sctiw'></tfoot>

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

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

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