使用C#,。Net 4,5,RestSharp v4.0.3
尝试在GoCardless中创建api_key
我创建了一个像这样的RestClient:
var client = new RestClient();
client.BaseUrl = SandboxBaseUrl;
client.Authenticator = new HttpBasicAuthenticator(apiKeyId, apiKey);
client.AddDefaultHeader("GoCardless-Version", Properties.Settings.Default.GoCardlessVersion);
client.AddDefaultHeader("Accept", "application/json");
client.AddDefaultHeader("content-type", "application/json");
request.AddHeader("content-type", "application/json");
当我发布到GoCardless时,我收到了错误
{"error":{"message":"'Content-Type' header must be application/json or application/vnd.api+json ......
答案 0 :(得分:0)
经过大量无结果的搜索,我放弃并使用旧版StackOverflow帖子中的解决方案。如
// Create the Json for the new object
StringBuilder requestJson = new StringBuilder();
var requestObject = new { api_keys = new { name = name, links = new { role = role } } };
(new JavaScriptSerializer()).Serialize(requestObject, requestJson);
...
// Set up the RestSharp request
request.Parameters.Clear();
request.AddParameter("application/json", requestJson, ParameterType.RequestBody);
我可以看出为什么会这样 - 甚至可能是RestSharp这样做的意图。