在我问这个问题之前,我想指出,我已经看过www.developer.intuit.com的API文档,我还搜索了堆栈溢出。我之所以提到这一点,是因为我希望避免任何包括“为什么不阅读文档或进行搜索”的回复。据我所知,这一点实际上没有在文档中得到解决。
我试图使用一个HttpClient对象调用API,而我所缺少的唯一细节就是关于如何准确构造授权头的细节。
这是构建和处理API调用的代码块:
string jsonString = JsonConvert.SerializeObject(customer, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
var httpResponse = new HttpResponseMessage();
using (var client = new HttpClient()) {
client.DefaultRequestHeaders.Add("Accept", "application/json;charset=UTF-8");
client.DefaultRequestHeaders.Add("ContentType", "application/json;charset=UTF-8");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppController.access_token);
httpResponse = await client.PostAsync(uri, httpContent);
}我做了Coder1409建议的更改,并在上面的代码块中反映了这一更改。我仍然收到一个错误,但是错误号已经改变了。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2017-12-04T07:57:11.131-08:00">
<Fault type="AuthenticationFault">
<Error code="100">
<Message>General Authentication Error</Message>
<Detail>AuthenticationErrorGeneral: Internal Server Error , statusCode: 500</Detail>
</Error>
</Fault>
</IntuitResponse>发布于 2017-12-04 15:51:39
你认为你应该改变这一行
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("OAuth2", AppController.access_token);到这个
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AppController.access_token);https://stackoverflow.com/questions/47636771
复制相似问题