Answer the question
In order to leave comments, you need to log in
How to make a post request with npm request?
I'm trying to send a request via the VK API to upload a file, but I'm getting an empty object in response.
In PHP with curl, everything is clear:
$imgserv = 'картинка';
$postparam = 'URL для загрузки';
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL,$imgserv);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postparam);
$Request_step2 = curl_exec($ch);
curl_close($ch);
$Responce_step2=json_decode($Request_step2);
// В ответ получаю загруженный файл
/*[server] => 630930
[photo] => [{"photo":"328f37ab63:x","sizes":,"kid":"8e182ed1d07eb145b51d697658a22e6c","debug":"xsxmxxxoxpxqxrx"}]
[hash] => ebb1e7b32497227ed726a334409ae238
)
*/
var postParams = {
"file1": "@" + image
};
request.post(url, postParams, function(e, res, body) {
if(e) console.log(e);
console.log(JSON.parse(body));
});
{ server: 630930,
photo: '[]',
hash: '05811d209a749a42ae9d87c72fc42b15' }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question