不能在node.js中创build这个特定的http修补请求

这里是我如何做curl请求:

curl -v --request PATCH -H "Authorization: token TOKEN-VALUE-FROM-PREVIOUS-CALL" -d '{"description": "updated gist","public": true,"files": {"file1.txt": {"content": "String file contents are now updated"}}}' https://api.github.com/gists/GIST-ID-FORM-PREVIOUS-CALL 

我已经尝试了几个节点库来做出“补丁”请求,但没有成功。 我也可以在客户端用jQuery.ajax做同样的事情,但不能在服务器端工作。 提前致谢。

       

网上收集的解决方案 "不能在node.js中创build这个特定的http修补请求"

使用Node.js中的本地HTTP请求function,您可以按如下方式提出请求 –

 var qs = require("querystring"); var http = require("https"); var options = { "method": "PATCH", "hostname": "api.github.com", "port": null, "path": "/gists/GIST-ID-FORM-PREVIOUS-CALL", "headers": { "authorization": "token TOKEN-VALUE-FROM-PREVIOUS-CALL", "cache-control": "no-cache", "content-type": "application/x-www-form-urlencoded" } }; var req = http.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function () { var body = Buffer.concat(chunks); console.log(body.toString()); }); }); req.write(qs.stringify( { "description": "updated gist", "public": "true", "files": { "file1.txt": { "content": "String file contents are now updated" } } })); req.end();