gpt4 book ai didi

c# - jet.com 合作伙伴 API - Rest、JSON、RestSharp?

转载 作者:行者123 更新时间:2023-11-30 17:41:20 26 4
gpt4 key购买 nike

我有一个用 VB.net 编写的自定义订单管理系统。我现在需要使用 jet.com 合作伙伴 api 与他们集成。我相信这对你们这些 Web 专家来说并不难,但我对 RESTful 调用 API 没有太多经验。

documentation I have说:

Jet API Security Flow
The following security flow is the assumed flow for accessing Jet API functions that require authorization:

User submits his/her credentials over SSL/TLS to Jet API /api/Token endpoint via HTTPS POST request, like below:

POST https://merchant-api.jet.com/api/Token HTTP/1.1 
Host: merchant-api.jet.com
Content-Type: application/json; charset=utf-8
Content-Length: 42

{"user":"dummy@jet.com","pass":"XXXXXXXX"}

/api/Token endpoint is a single point of authentication for Jet API users. Therefore, it does not require either authentication or authorization.

If the user successfully authenticated, the security (bearer) token is returned back over SSL/TLS carrying claims associated with the user encoded and signed:

HTTP/1.1 200 OK 
Cache-Control: no-store
Pragma: no-cache
Content-Length: XXX
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.0
Set-Cookie: auth0=XXX...XX; path=/; secure; httponly
Server: nginx/1.7.1
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 06 Aug 2014 13:50:17 GMT
Set-Cookie: SERVERID=03-4BRURJ6FFLMCK; path=/

{"id_token":"XXX...XX","access_token":"XXX...XX","token_type":"bearer"}

Token is contained in JSON node id_token that should be used in the following HTTP requests to Jet API as authorization vehicle (see article 4 below) until it expires or gets refreshed.

If not authenticated at the /api/Token endpoint, the user gets back HTTP response carrying header HTTP/1.1 401 Unauthorized. Having the above bearer token, the user then should provide it when calling other Jet API endpoints as part of HTTPS requests within Authorization header. This header has the following form: Authorization: Bearer If the user has proper permissions associated with the token he/she will be allowed to access the endpoints and/or specific data assigned by those permissions. The request will be executed and response will be defined by the correspondent called API function, otherwise HTTP/1.1 401 Unauthorized response is returned back.

Bearer tokens provided to Jet API users have a limited lifetime. However, until the token expires, the bearer token will be a full substitute for user credentials, so the token must be handled as private cryptographic material.

谁能告诉我一些示例代码以在 C# 中执行此操作?我当时认为使用 RestSharp 会有所帮助,但也没有任何这方面的经验。

对于他们的 API,我需要:

  1. 授权我的 API 调用
  2. 上传 JSON 格式的产品
  3. 检索订单信息
  4. 等等

因此,我停留在第一阶段,授权我的 API 调用。

最佳答案

您好,您可以使用此示例代码,我使用 this link 生成了此代码

var client = new RestClient("https://merchant-api.jet.com/api/token/");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "xxxx");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("authorization", "Basic xxxx");
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\"user\":\"xxxx\",\"pass\":\"xxxx\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

关于c# - jet.com 合作伙伴 API - Rest、JSON、RestSharp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33179985/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com