我正在为一个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);
然而,该服务正在返回一个错误。
错误415:请使用“Content-Type: application/json; charset=utf-8”头部
为什么RestSharp没有传递头部?
request.RequestFormat = DataFormat.Json
为您设置了Content-Type标头。 - Randy James