gpt4 book ai didi

node.js - Node 中请求 GET 失败

转载 作者:太空宇宙 更新时间:2023-11-03 21:57:09 25 4
gpt4 key购买 nike

我正在从我的 node 后端向第 3 方 API 服务请求 GET
我收到403禁止的响应:

request("http://www.giantbomb.com/api/search/?api_key=my_api_key&field_list=name,image,id&format=json&limit=1&query=street%20fighter%203&resources=game",(err,res,body) => {
console.log(body);
})

在浏览器中查询相同的请求会返回预期的结果。
知道为什么会发生这种情况吗?

编辑:

记录响应正文,我收到以下页面(没有 JS):

<h1>Wordpress RSS Reader, Anonymous Bot or Scraper Blocked</h1>
<p>
Sorry we do not allow WordPress plugins to scrape our site. They tend to be used maliciously to steal our content. We do not allow scraping of any kind.
You can load our RSS feeds using any other reader but you may not download our content.
<a href='/feeds'>Click here more information on our feeds</a>
</p>
<p>
Or you're running a bot that does not provide a unique user agent.
Please provide a UNIQUE user agent that describes you. Do not use a default user agent like "PHP", "Java", "Ruby", "wget", "curl" etc.
You MUST provide a UNIQUE user agent. ...and for God's sake don't impersonate another bot like Google Bot that will for sure
get you permanently banned.
</p>
<p>
Or.... maybe you're running an LG Podcast player written by a 10 year old. Either way, Please stop doing that.
</p>

最佳答案

此服务需要 header 中的 User-Agent,请参阅此示例

const rp = require('request-promise')

const options = {
method: 'GET',
uri: 'http://www.giantbomb.com/api/search/?api_key=my_api_key&field_list=name,image,id&format=json&limit=1&query=street%20fighter%203&resources=game',
headers: { 'User-Agent': 'test' },
json: true
}

rp(options)
.then(result => {
// process result
})
.catch(e => {
// handle error
})

关于node.js - Node 中请求 GET 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37607498/

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