C# 无法使用RestSharp和GoCardless设置MIME类型

C# 无法使用RestSharp和GoCardless设置MIME类型,c#,mime,restsharp,gocardless,C#,Mime,Restsharp,Gocardless,使用C#、.NET4,5和RestSharp v4.0.3 试图在GoCardless中创建api_密钥 我创建了一个RestClient,如下所示: var client = new RestClient(); client.BaseUrl = SandboxBaseUrl; client.Authenticator = new HttpBasicAuthenticator(apiKeyId, apiKey); client.AddDefaultHeader("GoCardless-Vers

使用C#、.NET4,5和RestSharp v4.0.3

试图在GoCardless中创建api_密钥

我创建了一个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 ......

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

这可能是2012年RestSharp早期版本的重复