我正在尝试使用带有模块 的 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
在正文中。(参考:如何在 HTTP POST 请求中发送参数?)
但是,我Bad API request, invalid api_option
从 PasteBin 得到了一个。所以我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
?- 如何仅使用
request
模块发送 URL 编码的正文?