BIM 360 Field API 问题 V1:GET 请求与邮递员完美配合,使用 RestSharp "Unauthorized"响应



尝试在我的 C# 解决方案中实现var client = new RestClient("https://bim360field.autodesk.com/fieldapi/checklists/v1/06eede44-a707-4f0b-9529-78abea6e6bf5"); var request = new RestRequest(Method.GET); https://bim360field.autodesk.com/apidoc/index.html#fieldapi/checklists/v1/checklists_api_method_2。

我已经设置了一个示例 获取请求 在邮递员中。与form-data,x-www-form-urlencoded,无身份验证,持有者令牌完美配合。尝试将确切的 Restshap 请求代码从邮递员复制到我的 C# 应用程序。不起作用;始终以"未经授权"响应。尝试更改 cookie mngmt,以及身份验证窗口/nltm mngmt。没有帮助。

var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Connection", "keep-alive");
request.AddHeader("Content-Length", "91");
request.AddHeader("Accept-Encoding", "gzip, deflate");
request.AddHeader("Cookie", "OPTOUTMULTI_REF=b7027893-8564-4b33-8f1e-de0c175d38c6; OPTOUTMULTI_GEO=NL; utag_main=v_id:016639c85215001e1ab9f566c61201090006808800bd0$_sn:4$_ss:0$_st:1545042741235$ses_id:1545040922510%3Bexp-session$_pn:1%3Bexp-session; XSRF-TOKEN=YxM2BdzM19rML7OjKGZqcD0hAqv%2F225McEm8oB3m7No%3D; 75da74d446a8376e2cf6a286ff63573ab705f04c36540fdda21c1dbc1928d4e72cabf30a63e339690e88fc3801a93e44e6e3ddc20651f602d2c5eaaf49b21d61=f795a05c211085d994bf2e08996ff747");
request.AddHeader("Host", "bim360field.autodesk.com");
request.AddHeader("Postman-Token", "0b3c652d-462c-4aba-a661-476309792018,b4d4846c-a928-406f-837c-f16809a9bccd");
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "*/*");
request.AddHeader("User-Agent", "PostmanRuntime/7.15.2");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="ticket"rnrn{API_TICKET}rn------WebKitFormBoundary7MA4YWxkTrZu0gWrnContent-Disposition: form-data; name="project_id"rnrn049bf984-b8d1-4330-a17c-0832c6facf49rn------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);```
I expect that this code is also working with Restsharp. Do I miss anything?
  1. 对于您的 Cookie,您需要在客户端上设置一个 CookieContainer。

    Client = new RestClient(Request.GetEnvironment()) { CookieContainer = new System.Net.CookieContainer() };

  2. 您不需要邮递员令牌。您需要使用 API 提供的持有者令牌进行调用并将其添加到标头或参数中。

  3. 初始化 RestClient 时,您只想传递基本 URL。然后在 RestRequest 初始化期间传递 api 路径的其余部分。这将有助于将来想要使用相同的 cookie 点击多个端点时使用。

这是一个工作示例:

// (1) Build request 
var client = new RestClient();
client.BaseUrl = new System.Uri("https://bim360field.autodesk.com/");
// Set resource or end point 
var request = new RestRequest();
request.Resource = "/fieldapi/checklists/v1";
request.Method = Method.GET;
// Add parameters 
request.AddParameter("ticket", "{API_TICKET}");
request.AddParameter("project_id", "049bf984-b8d1-4330-a17c-0832c6facf49");
// (2) Execute request and get response
IRestResponse response = client.Execute(request); 

希望对您有所帮助!

相关内容

  • 没有找到相关文章

最新更新