I have a working piece of python:
url = "abc.com"
data = open('speech.wav', 'rb').read()
res = requests.post(url=url,
data=data,
headers={'Content-Type': 'application/octet-stream'})
which allows me to upload a wav file as a post request to the server. However, the below NodeJS code
var req = request.post('abc.com', function(err, resp, body) {
if (err) {
console.log('Error!');
} else {
console.log('URL: ' + body);
}
});
var form = req.form();
form.append('Content-Type', 'application/octet-stream');
form.append('data', fs.createReadStream('speech.wav'));
returns "Unsupported Media Type: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method."
What am I doing wrong on Node?
Try to send content-type as header, rather than in form. The content-type in form is considered for multipart form data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.