Make http request like php form does using nodejs

Viewed 128

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

2 Answers

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

I know you have finished the job, but there is a way to debug. You can use firefox for debugging request. debug

Related