我正在尝试create a new paste using the PasteBin API与request
模块如下:
var request = require("request");
request({
url : "http://pastebin.com/api/api_post.php",
method : "POST",
qs : {
"api_dev_key" : MY_DEV_KEY,
"api_option" : "paste",
"api_paste_code" : "random text"
}
},function(err,res,body){
...
});
我的理解是,由于该方法是POST
并且提供了查询字符串参数,因此qs
对象中的值将作为key=value
对存储在正文中。 (参考:How are parameters sent in an HTTP POST request?)
但是,我从PasteBin回来了一个Bad API request, invalid api_option
。所以我qazxs wwied来自我的终端的请求如下:
curl
这很有效。
所以这导致了两个问题:
curl -X POST "http://pastebin.com/api/api_post.php" -d "api_dev_key=[MY_DEV_KEY]&api_option=paste&api_paste_code=some+random+text"
请求并提供POST
时,参数的确切信息是什么?qs
模块发送URL编码的正文?将request
键重命名为对象中的qs
。 form
密钥用于指定URL末尾的查询字符串(例如,对于GET请求)。 qs
密钥用于指定表单URL编码的请求主体(例如,对于POST请求)。
对我来说同样的问题和我的解决方案对我来说是完美的。
form