【问题标题】:curl request with node.js使用 node.js 的 curl 请求
【发布时间】:2015-03-14 09:08:07
【问题描述】:

我想让以下 curl 在 node.js 中工作

curl -F source=@"pedestrian.png" -F model="pedestrian" localhost:3350/dpm/detect.objects

这就是我使用 require('request') 所拥有的:

 request('http://localhost:3350/dpm/detect.objects', function (error,    response, body) {
  console.log(response.statusCode);
  if (!error && response.statusCode == 201) {
    console.log(body) 
  }
 })

如何翻译 node.js 中的 curl 命令?如果有更好的解决方案,它不一定是请求库。

【问题讨论】:

    标签: javascript node.js curl


    【解决方案1】:

    看看documentation。您需要传递一个 formData 对象。

    var formData = {
      source: fs.createReadStream(__dirname + '/pedestrian.jpg'),
      model: 'pedestrian'
    };
    
    request.post({ 
        url:'http://localhost:3350/dpm/detect.objects', 
        formData: formData 
      }, function (err, httpResponse, body) {
        if (err) {
          return console.error('upload failed:', err);
        }
        console.log('Upload successful!  Server responded with:', body);
      }
    );
    

    【讨论】:

      猜你喜欢
      • 2019-02-08
      • 2015-08-10
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-07
      • 2017-10-31
      • 2014-08-04
      相关资源
      最近更新 更多