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

时间:2021-03-23 16:19:54

标签: c# api request postman

我在 Postman 中成功地完成了这个 API 请求,它给我带来了很好的回报。

邮递员结果: https://prnt.sc/10tlrbr

但是当我尝试执行 Postman 自动生成的 RestSharp 代码时,它会像下面一样返回禁止。

自动生成的 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>

为 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);

自动生成的标题: https://prnt.sc/10tlnfo

您可以在没有 oauth_token 或这样的参数的情况下尝试此代码:

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

我尝试过 Postman 自动生成的标头并更改用户代理,但没有任何改变。

我遗漏了什么或做错了什么?

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

1 个答案:

答案 0 :(得分:0)

你应该看看 HTML:

<块引用>

标题:Pease 验证您是人类。

访问此页面已被拒绝,因为我们认为您正在使用自动化工具浏览 网站。

这可能是由于以下原因造成的:

  • Javascript 被某个扩展程序禁用或阻止(例如广告拦截器)
  • 您的浏览器不支持 cookie

请确保您的浏览器启用了 Javascript 和 cookie,并且您没有 阻止它们加载。

此外,您不应在参数中设置 oauth 令牌,而应通过 Postman 的身份验证功能设置。然后它也将正确地出现在生成的代码中。 Here 您可以获得更多信息。