【问题标题】:Cannot set MIME type using RestSharp and GoCardless无法使用 RestSharp 和 GoCardless 设置 MIME 类型
【发布时间】:2015-04-27 18:10:51
【问题描述】:

使用 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 ......

【问题讨论】:

标签: c# mime restsharp gocardless


【解决方案1】:

经过大量徒劳的搜索后,我放弃了并使用了旧 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 这样做的意图。

【讨论】:

    猜你喜欢
    • 2020-11-26
    • 1970-01-01
    • 2015-06-16
    • 2011-07-04
    • 1970-01-01
    • 2021-02-27
    • 2019-05-28
    • 2012-09-10
    • 2015-09-17
    相关资源
    最近更新 更多