Set 'Content-Type' header using RestSharp

后端 未结 5 1012
眼角桃花
眼角桃花 2020-12-08 19:39

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

The API states:

When creating

5条回答
  •  甜味超标
    2020-12-08 19:51

    Although this is a bit old: I ran into the same problem.. seems some attributes such as "content-type" or "date" cannot be added as parameter but are added internally. To alter the value of "content-type" I had to change the serialzer setting (altough I didn`t use it because I added a json in the body that was serialized before!)

    RestClient client = new RestClient(requURI);
    RestRequest request = new RestRequest(reqPath, method);
    request.JsonSerializer.ContentType = "application/json; charset=utf-8";
    

    as soon as I did this the header showed up as intended:

     System.Net Information: 0 : [5620] ConnectStream#61150033 -   Header 
     {
      Accept: application/json, application/xml, text/json, text/x-json, text/javascript, text/xml
      User-Agent: RestSharp 104.1.0.0
      Content-Type: application/json; charset=utf-8
      ...
     }
    

提交回复
热议问题