node 【request】模块post的EncType问题
发布于 8 个月前 作者 youngdeer 357 次浏览 来自 问答

API中的解释: application/x-www-form-urlencoded (URL-Encoded Forms) URL-encoded forms are simple.

request.post('http://service.com/upload', {form:{key:'value'}})
// or 
request.post('http://service.com/upload').form({key:'value'})
// or 
request.post({url:'http://service.com/upload', form: {key:'value'}}, function(err,httpResponse,body){ /* ... */ })

使用上面的post是否和下面的效果一样

form#xxx(method="post" action="xxx")
       input(type="hidden" name="xxx" value="xxx")
	   
$("#xxx").submit();
1 回复
request.post({url:'http://service.com/upload', formData: formData}, function optionalCallback(err, httpResponse, body) {
  if (err) {
    return console.error('upload failed:', err);
  }
  console.log('Upload successful!  Server responded with:', body);
});

解决了,不小心把form:{key:‘value’}写成了formData:{key:‘value’} 这样EncType 就是multipart/form-data (Multipart Form Uploads)这种了

回到顶部