通过 HttpClient 访问 Design Automation API v3 时出现 404
404 when accessing Design Automation API v3 through HttpClient
运行 调用 Postman 中的 Design Automation API 工作得很好,但是当我尝试使用 HttpClient 在 C# 中进行相同的调用时,它们失败并显示 404,这似乎实际上隐藏了身份验证错误:
{
"developerMessage":"The requested resource does not exist.",
"userMessage":"",
"errorCode":"ERR-002",
"more info":"http://developer.api.autodesk.com/documentation/v1/errors/err-002"
}
link 导致身份验证错误:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>1F52E60A45AEF429</RequestId>
<HostId>
[ Some base64 ]
</HostId>
</Error>
我正在按照有关如何使用 HttpClient 的示例进行操作,但我可能遗漏了一些内容。我成功获得了访问令牌,运行
var client = new HttpClient
{
BaseAddress = new Uri("https://developer.api.autodesk.com/da/us-east")
};
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue(TokenType, AccessToken);
然后
var result = await client.GetAsync("/v3/forgeapps/me");
以上json为结果内容。我在 Postman 中使用相同的访问令牌并且它有效。
我会在 HttpRequestMessage 中结束端点 headers 和 httpmethod。然后发送并赋值给HttpResponseMessage。
var client = new HttpClient
{
BaseAddress = new Uri("https://developer.api.autodesk.com/da/us-east/")
};
//throw the endpoint and HttpMethod here. Could also be HttpMethod.Post/Put/Delete (for your future reference)
var request = new HttpRequestMessage(HttpMethod.Get, "v3/forgeapps/me");
//also maybe try throwing the headers in with the request instead of the client
request.Headers.Add(TokenType, AccessToken);
// send the request, assign to response
HttpResponseMessage response = await client.SendAsync(request);
//then, we can grab the data through the Content
string result = await response.Content.ReadAsStringAsync();
运行 调用 Postman 中的 Design Automation API 工作得很好,但是当我尝试使用 HttpClient 在 C# 中进行相同的调用时,它们失败并显示 404,这似乎实际上隐藏了身份验证错误:
{
"developerMessage":"The requested resource does not exist.",
"userMessage":"",
"errorCode":"ERR-002",
"more info":"http://developer.api.autodesk.com/documentation/v1/errors/err-002"
}
link 导致身份验证错误:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>1F52E60A45AEF429</RequestId>
<HostId>
[ Some base64 ]
</HostId>
</Error>
我正在按照有关如何使用 HttpClient 的示例进行操作,但我可能遗漏了一些内容。我成功获得了访问令牌,运行
var client = new HttpClient
{
BaseAddress = new Uri("https://developer.api.autodesk.com/da/us-east")
};
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue(TokenType, AccessToken);
然后
var result = await client.GetAsync("/v3/forgeapps/me");
以上json为结果内容。我在 Postman 中使用相同的访问令牌并且它有效。
我会在 HttpRequestMessage 中结束端点 headers 和 httpmethod。然后发送并赋值给HttpResponseMessage。
var client = new HttpClient
{
BaseAddress = new Uri("https://developer.api.autodesk.com/da/us-east/")
};
//throw the endpoint and HttpMethod here. Could also be HttpMethod.Post/Put/Delete (for your future reference)
var request = new HttpRequestMessage(HttpMethod.Get, "v3/forgeapps/me");
//also maybe try throwing the headers in with the request instead of the client
request.Headers.Add(TokenType, AccessToken);
// send the request, assign to response
HttpResponseMessage response = await client.SendAsync(request);
//then, we can grab the data through the Content
string result = await response.Content.ReadAsStringAsync();