javascript - Node.js - 带有 'request' 模块的 PUT

标签 javascript node.js http-put

我正在使用 Node.js 中的 request 模块来执行 put 请求。我的代码是这样的

var request = require('request');
var data = {foo: "bar", woo: "car"};

request({
   method: 'PUT',
   uri: myURL,
   multipart: [{
       'content-type':'application/json',
       body: JSON.stringify(data) 
   }]
}, function(error, request, body){
   console.log(body);
});

当我运行它时,我得到一个错误:

“不支持的内容类型:application/json”

最佳答案

就这样试试吧:

request({ url: url, method: 'PUT', json: {foo: "bar", woo: "car"}}, 回调)

关于javascript - Node.js - 带有 'request' 模块的 PUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21393706/

相关文章:

node.js - 使用lodash中的键值合并对象数组?

c++ - 通过从 C++ 到 nodejs 进程的套接字连接发送 250ms UDP 价格滴答,为什么?

node.js - 当我的 Lambda 有权访问 S3 存储桶时,为什么我的 GetObjectRequest 返回 403 访问被拒绝错误?

javascript - http put 的 AngularJS(500 内部服务器错误)

http-post - Liquidsoap http.put/post 未发布数据

ruby - 使用 ruby​​ Net :HTTP API to a remote apache server failing with 409 Conflict 上传文件

php - 需要通过 PHP 压缩 CSS 和 JavaScript,但需要了解性能影响以及如何实现?

javascript - 如何在保持响应速度的同时将 YouTube 视频居中?

javascript - 关于使用 Tabindex 和 javascript/jquery 使 "tabbing"更容易的建议

javascript - 如何捕获文本中某个单词后面出现的多个数字?