fent / node-miniget

A small http(s) GET library.
MIT License
55 stars 17 forks source link

Handling POST requests #55

Closed gatecrasher777 closed 3 years ago

gatecrasher777 commented 3 years ago

Yes, it's called miniget but still... is there a designed way to make post requests with

let body = await miniget('http://mywebsite.com/submit/',options).text();

since neither the stream nor request is exposed? I made post requests work quite easily with just one extra line of code in the source:

if (options.method === "POST") activeRequest.write(options.postData);

just before the line that ends the request:

activeRequest.end();

Then the request options contain:

options.method = 'POST'
options.header.content-length' = Buffer.byteLength(data,'utf8'),
options.postData = data;

Is this useful, or is there an elegant way of achieving the same without altering the project source code?

TimeForANinja commented 3 years ago

had a pr merged few days ago to allow for post requests

since neither the stream nor request is exposed?

guess you missed sth here 😉 check out my usage here https://github.com/TimeForANinja/node-ytsr/blob/wip-api-adjustments/lib/utils.js#L77

gatecrasher777 commented 3 years ago

Aha! That's perfect, thanks.