繁体   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