Warm tip: This article is reproduced from serverfault.com, please click

Make http request like php form does using nodejs

发布于 2020-11-26 19:26:40

I need to make the same request as the form in the picture does, but using nodejs. I tried code below, but it didn't work. To be more accurate, code below executing around 5s and after that shutdown without response from server.

import got from 'got';
import * as fs from 'fs';
import * as FormData from 'form-data';
import * as path from 'path';

const fileBody = new FormData();

fileBody.append('a','FilesMan');
fileBody.append('c','/app/4');
fileBody.append('ne','');
fileBody.append('p1','uploadFile');
fileBody.append('charset','UTF-8');
fileBody.append('f[]', fs.createReadStream(path.resolve(__dirname, '../test.php')), { filename: 'test.php' });

got.post('http://someurl', { body: fileBody });

Php form

Questioner
vipe4ka-visko4ka
Viewed
0
vipe4ka-visko4ka 2020-11-29 02:01:31

I solved problem by using method submit provided by form-data npm package instead of using got library