2016-06-03 5 views
2

node 백엔드에서 타사 API 서비스에 GET을 요청하고 있습니다.노드에서 GET 요청이 실패했습니다.

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

브라우저에서 동일한 요청 예상 된 결과를 반환하는 쿼리 :
나는 403 forbidden의 반응을 얻고있다.
이것이 일어날 수있는 이유는 무엇입니까?

편집 : 응답 본체 로깅은

, I합니다 (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> 
+0

해당 URL의 형식이 잘못되었습니다. 왜 쿼리 매개 변수 앞에 슬래시가 있습니까? 소프트웨어가 브라우저에 사용하고있는 URL을 로깅, 복사 및 붙여 넣기하는 것을 고려 했습니까? 아니면 다시 입력 했습니까? – jonrsharpe

+0

내 코드에서와 똑같이 복사하여 브라우저에 붙여 넣습니다. 브라우저에서 슬래시를 제거하려고했지만 요청을 보낼 때 다시 추가되었습니다. – itaied

+0

브라우저 (쿠키 등)에 어떤 상태가 있습니까? 아직 익명의 브라우저 창에서 작동합니까? – jonrsharpe

답변

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 
    }) 
1

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); 
}) 
+0

'User-Agent'를'request '로 설정해야합니까? 왜냐하면 나는 여전히 '403' 같은 것을 얻고 있기 때문입니다. – itaied

+0

은 http://www.giantbomb.com/api/documentation 설명서를 확인했으며 User-Agent 헤더 텍스트에 대한 사용자 정의 요구 사항이 없으므로 비어 있지 않은 문자열을 설정할 수 있습니다. 0, "offset": 0, "number_of_page_results": 0, "number_of_total_results": 0, "status_code": 백엔드에서이 응답을 받는다. : 100, "results": []}' – kaxi1993

+0

우선, 시간 내 주셔서 대단히 감사합니다. 브라우저에 가짜 API 키를 보내면 내가 게시 한 것과 동일한 결과가 나타납니다. 내 노드 앱에서 동일한 가짜 API 키를 보내면 브라우저에서 금지 된 403을 받고 브라우저에서는 200 OK입니다. 나는 정말로 그것을 얻지 않는다. ... – itaied

관련 문제