簡體   English   中英

GET 請求在瀏覽器和 Postman 中有效,但是在使用 HttpClient 和 RestSharp 時我得到了未經授權

[英]GET request works in browser and Postman, but I get Unauthorized when using HttpClient and RestSharp

我通過 Postman 發出請求

“https:// APIKEY密碼@ myexampledomain.myshopify.com / api/2021-04/custom_collections.json

我得到了真實的回應:

 { "custom_collections": [ { "id": 264277491901, "handle": "baran-kategori", "updated_at": "2021-04-08T18:05:03+03:00", "published_at": "2021-04-05T16:40:08+03:00", "sort_order": "best-selling", "template_suffix": "", "published_scope": "web", "title": "Baran Kategori", "body_html": "" }, { "id": 264276377789, "handle": "category1", "updated_at": "2021-04-06T14:49:26+03:00", "published_at": "2021-04-05T16:12:36+03:00", "sort_order": "best-selling", "template_suffix": "", "published_scope": "web", "title": "Category1", "body_html": "" }, { "id": 264362623165, "handle": "nike", "updated_at": "2021-04-08T18:05:03+03:00", "published_at": "2021-04-06T16:17:49+03:00", "sort_order": "best-selling", "template_suffix": "", "published_scope": "web", "title": "Nike", "body_html": "" } ] }

當嘗試通過 httpclient 或 restsharp 執行相同的 GET 時,我得到了 401 未授權。

{StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Date: Thu, 08 Apr 2021 16:12:33 GMT
  Transfer-Encoding: chunked
  Connection: keep-alive
  X-Sorting-Hat-PodId: 188
  X-Sorting-Hat-ShopId: 56072536253
  Referrer-Policy: origin-when-cross-origin
  X-Frame-Options: DENY
  X-ShopId: 56072536253
  X-ShardId: 188
  WWW-Authenticate: Basic Realm="Shopify API Authentication"
   Content-Type: application/json; charset=utf-8
  Content-Length: 89
}}

當嘗試通過 httpclient 或 restsharp 執行相同的 GET 時,我得到了 401 未授權。

WWW-Authenticate: Basic Realm="Shopify API 身份驗證"

HTTP 401 Unauthorized 錯誤表示請求尚未應用,因為它缺少目標資源的有效身份驗證憑據。

請檢查您是否在Authorization header 字段中提供了身份驗證憑據。

Authorization: Basic Your_base64EncodedAuthenticationString_Here

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM