c# - API 请求在 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/10tInfo
您可以在没有 oauth_token 或参数的情况下尝试此代码:
var client = new RestClient("https://api.foursquare.com/v2/checkins/add");
我已经尝试过 Postman 自动生成的标题并更改了用户代理,但没有任何改变。
我错过了什么或做错了什么?
API 文档: https ://developer.foursquare.com/docs/api-reference/checkins/add/
解决方案
您应该查看 HTML:
标题:请验证您是人类。
访问此页面已被拒绝,因为我们认为您正在使用自动化工具浏览该网站。
这可能是由于以下原因而发生的:
- 扩展程序禁用或阻止了 Javascript(例如广告拦截器)
- 您的浏览器不支持 cookie
请确保在您的浏览器上启用了 Javascript 和 cookie,并且您没有阻止它们加载。
此外,您不应在参数中设置 oauth 令牌,而应通过 Postman 的身份验证功能。然后它也将正确地出现在生成的代码中。在这里您可以获得更多信息。
推荐阅读
- typescript - connect-redis.redis 和 ioredis.redis 类型不兼容
- python - 在 django rest 框架中缓存查询集?
- python - 将协程扔到事件循环而不阻塞
- delphi - 当我打开 Windows 的 WiFi 菜单时停止工作是正常的 Indy 行为吗?
- mule4 - Mule 4 中用于多个流的 API 自动发现
- architecture - 确定四个级间寄存器中每一个的最小大小(以位为单位)
- reactjs - 将 React 应用程序部署到 Github 时 npm run deploy 失败
- html - 垂直对齐 td 中 contenteditable div 中的文本,其中 div 与 td 大小相同
- python - 正确显示绘图
- javascript - Javascript:我可以使用 JS 将 HTML 元素从一个页面复制到另一个页面吗?