小编Sha*_*and的帖子

使用RestSharp设置'Content-Type'标头

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

API声明:

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

这就是我的代码:

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);
Run Code Online (Sandbox Code Playgroud)

然而; 服务返回"错误415:请使用'Content-Type:application/json; charset = utf-8'标题." 为什么RestSharp没有传递标题?

c# http-headers restsharp

32
推荐指数
3
解决办法
7万
查看次数

标签 统计

c# ×1

http-headers ×1

restsharp ×1