2014-04-19 5 views
0

Javascript/Node 모듈 요청의 .post() 편리한 메소드를 사용하려고합니다. 콜백을 수락합니까? 그냥 ... 후속 내가 대신 restler 사용하고 나는 그것을 더 나은 방법으로 찾을 수 있습니다 :노드 요청 모듈 .Post() 편리한 메소드 및 콜백

var request = require('request'); 
request.post({url: 'https://identity.api.foo/v2.0', body: JSON.stringify({ 
     'auth': { 
      "KSKEY:apiKeyCredentials": { 
       "username": "joe", 
       "apiKey": "10677bad" 
        } 
     } 
}), function (e, r, body) { 
    console.log(e); 
    console.log(r); 
    console.log(body); 
}); 

[email protected] ~ $ node try.js 

/home/one/try.js:9 
}), function (e, r, body) { 
      ^
SyntaxError: Unexpected token (
    at Module._compile (module.js:439:25) 
    at Object.Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Function.Module.runMain (module.js:497:10) 
    at startup (node.js:119:16) 
    at node.js:902:3 
[email protected] ~ $ 

편집 : 그것은 이것에 대해 불평 할 이유를 나는 이해하지 않습니다. - 이와 같은 도구가 필요한 사람이라면

+0

문서에서 이름이 지정된 함수식이 필요합니다. – adrichman

+0

문서에서 본 것에서부터 그렇습니다. 하지만 어쨌든 하나를 시도하고 SyntaxError있어 : 예기치 않은 기능에 대한 식별 bob (e, r, body) {} – dman

답변

1

두 번째 인수 (콜백) 전에 전달할 객체를 닫아야합니다.

var request = require('request'); 
request.post({url: 'https://identity.api.foo/v2.0', body: JSON.stringify({ 
     'auth': { 
      "KSKEY:apiKeyCredentials": { 
       "username": "joe", 
       "apiKey": "10677bad" 
        } 
     } 
    }) 
}, function...