亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過 HttpClient 訪問 Design Automation API v3 時出現 404

通過 HttpClient 訪問 Design Automation API v3 時出現 404

C#
森林海 2023-05-13 16:10:52
在 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"}該鏈接導致身份驗證錯誤:<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 中使用相同的訪問令牌并且它有效。
查看完整描述

1 回答

?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊

我會在 HttpRequestMessage 中包含端點、標頭和 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();


查看完整回答
反對 回復 2023-05-13
  • 1 回答
  • 0 關注
  • 153 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號