请求节点中的GET失败

时间:2016-06-03 06:36:29

标签: node.js httprequest

我从GET后端请求node到第三方API服务。
我收到403 forbidden的回复:

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>

2 个答案:

答案 0 :(得分:1)

在此请求中包含User-Agent标头

var options = {
  url: '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': 'request'
  }
};

request(options, (err,res,body) => {
    console.log(body);
})

答案 1 :(得分:1)

此服务需要标头中的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
  })