简体   繁体   English

API 请求适用于 Postman 但不适用于生成的代码

[英]API request works in Postman but not working on generated code

I am successfully doing this API request in Postman and it returns me well.我在 Postman 中成功地执行了这个 API 请求,它返回给我很好。

Postman results: https://prnt.sc/10tlrbr Postman 结果: https://prnt.sc/10tlrbr

But when I try to do Postman's auto-generated RestSharp code it's returning forbidden just like below.但是,当我尝试执行 Postman 自动生成的 RestSharp 代码时,它会像下面一样返回禁止。

Auto-generated RestSharp code results:自动生成的 RestSharp 代码结果:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Access to this page has been denied.</title> <link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet"> <style> html, body { margin: 0; padding: 0; font-family: 'Open Sans', sans-serif; color: #000; } a { color: #c5c5c5; text-decoration: none; } .container { align-items: center; display: flex; flex: 1; justify-content: space-between; flex-direction: column; height: 100%; } .container > div { width: 100%; display: flex; justify-content: center; } .container > div > div { display: flex; width: 80%; } .customer-logo-wrapper { padding-top: 2rem; flex-grow: 0; background-color: #fff; visibility: hidden; } .customer-logo { border-bottom: 1px solid #000; } .customer-logo > img { padding-bottom: 1rem; max-height: 50px; max-width: 100%; } .page-title-wrapper { flex-grow: 2; } .page-title { flex-direction: column-reverse; } .content-wrapper { flex-grow: 5; } .content { flex-direction: column; } .page-footer-wrapper { align-items: center; flex-grow: 0.2; background-color: #000; color: #c5c5c5; font-size: 70%; } @media (min-width: 768px) { html, body { height: 100%; } } </style> <!-- Custom CSS -->  </head> <body> <section class="container"> <div class="customer-logo-wrapper"> <div class="customer-logo"> <img src="" alt="Logo"/> </div> </div> <div class="page-title-wrapper"> <div class="page-title"> <h1>Please verify you are a human</h1> </div> </div> <div class="content-wrapper"> <div class="content"> <div id="px-captcha"> </div> <p> Access to this page has been denied because we believe you are using automation tools to browse the website. </p> <p> This may happen as a result of the following: </p> <ul> <li> Javascript is disabled or blocked by an extension (ad blockers for example) </li> <li> Your browser does not support cookies </li> </ul> <p> Please make sure that Javascript and cookies are enabled on your browser and that you are not blocking them from loading. </p> <p> Reference ID: #93318f50-8bf1-11eb-85a7-c78da2bc2a80 </p> </div> </div> <div class="page-footer-wrapper"> <div class="page-footer"> <p> Powered by <a href="https://www.perimeterx.com/whywasiblocked">PerimeterX</a> , Inc. </p> </div> </div> </section> <!-- Px --> <script> window._pxAppId = 'PX0UqK4c76'; window._pxJsClientSrc = '/0UqK4c76/init.js'; window._pxFirstPartyEnabled = true; window._pxVid = ''; window._pxUuid = '93318f50-8bf1-11eb-85a7-c78da2bc2a80'; window._pxHostUrl = '/0UqK4c76/xhr'; </script> <script src="/0UqK4c76/captcha/captcha.js?a=c&u=93318f50-8bf1-11eb-85a7-c78da2bc2a80&v=&m=0"></script> <!-- Custom Script -->  </body> </html>

Auto-generated RestSharp code for C#:为 C# 自动生成的 RestSharp 代码:

var client = new RestClient("https://api.foursquare.com/v2/checkins/add?oauth_token=XXX&venueId=4c0c79aa2466a593b4337621&ll=36.86361515148467,30.64172744750977&v=20210322");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Auto-generated headers: https://prnt.sc/10tlnfo自动生成的标题: https://prnt.sc/10tInfo

You can try this code without an oauth_token or parameter like this:您可以在没有 oauth_token 或参数的情况下尝试此代码:

var client = new RestClient("https://api.foursquare.com/v2/checkins/add");

I have tried the Postman auto-generated headers and change user-agent but nothing changed.我已经尝试了 Postman 自动生成的标题并更改了用户代理,但没有任何改变。

What am I missing or doing something wrong?我错过了什么或做错了什么?

API docs: https://developer.foursquare.com/docs/api-reference/checkins/add/ API 文档: https://developer.foursquare.com/docs/api-reference/checkins/add/

You should look at the HTML:您应该查看 HTML:

Title: Pease verify you are a human.标题:请验证您是人类。

Access to this page has been denied because we believe you are using automation tools to browse the website.访问此页面已被拒绝,因为我们认为您正在使用自动化工具浏览该网站。

This may happen as a result of the following:这可能是由于以下原因而发生的:

  • Javascript is disabled or blocked by an extension (ad blockers for example) Javascript 被扩展禁用或阻止(例如广告拦截器)
  • Your browser does not support cookies您的浏览器不支持 cookies

Please make sure that Javascript and cookies are enabled on your browser and that you are not blocking them from loading.请确保在您的浏览器上启用了 Javascript 和 cookies 并且您没有阻止它们加载。

Also you should not set the oauth token within the Parameters but via the Authenticate functionality of Postman.此外,您不应在参数中设置 oauth 令牌,而应通过 Postman 的身份验证功能。 Then it will be also correctly in the generated code as well.然后它也将正确地出现在生成的代码中。 Here you get more Info. 在这里您可以获得更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM