不工作这是我的HTTP POST代码,在本地主机上运行:Instagram的API通过的NodeJS
if(headers['Content-Type'] == undefined)
headers['Content-Type'] = 'application/x-www-form-urlencoded';
var post_options = {
host: host,
path: path,
port: port,
method: 'POST',
headers: headers
};
if(headers['Content-Type'] == "application/json"){
post_options["json"] = true;
var post_data = JSON.stringify(body);
}else
var post_data = querystring.stringify(body);
var post_req = http.request(post_options, function(res) {
var body = '';
console.log("INSIDE CALLBACK HTTP POST");
res.setEncoding('utf8');
res.on('data', function (chunk) {
body += chunk;
console.log('Response: ' + chunk);
});
res.on('end', function() {
var post = querystring.parse(body);
console.log("FINAL BODY:",post);
});
//console.log("RESPONSE in http POST:",res);
});
// post the data
console.log("WRITING HTTP POST DATA");
var sent_handler = post_req.write(post_data);
console.log("POST_REQ:",post_req);
console.log("sent_handler:",sent_handler);
post_req.end();
这里是我发送到Instagram的准确信息:
host
=“api.instagram。 COM”path
= “/ OAuth的/的access_token”body
如下:body [“client_id”] = CLIENT_ID;
body [“client_secret”] = CLIENT_SECRET;
body [“grant_type”] =“authorization_code”;
body [“redirect_uri”] = AUTHORIZATION_REDIRECT_URI;
body [“code”] = login_code;
body [“scope”] =“public_content”;
headers
= {}(空,假定报头[ '内容 - 类型'] ==未定义为真)重要:
sent_handler
返回false的的console.log为“FINAL BODY”(变量
post
)返回“{}”
要注意:通讯使用curl与api instagram作品。所以我真的相信这个问题出现在nodejs代码的某些部分。
有没有人有任何想法?请询问是否需要更多信息
请不要混淆,并从你的if语句它只是要求匹配省略括号发生灾难,并大大降低了可读性。 – brandonscript
@brandonscript关于请求可能发生什么的任何想法? – Fane