Skip to main content

Posts

Showing posts with the label FormData

Requests with Node

This is going to be just a quick entry today, and when I was thinking of what to write about, it dawned on me just how much research I had gone in to in making different types of requests (https) in Node.  Took me a while to first have it so it was able to switch between a GET and a POST of JSON data, but then when I needed to make changes on how I would post Form data (including a file attachment) was another kettle of fish - steam rolled at every turn. So - let me help take you out of your misery.  Here is my base function and its required required libraries: An example of using this would go like follows. form = {      file: '@/tmp/path/to/filename.txt',      comment: '' }; request("POST","www.server.com","/",{},{'Custom-Header':'Custom-Value'},form) .then(res=>{ //console.log(res); //... }) .catch(err=>{console.log(`Request Error: ${err}`)}); This will send form data, including the filename you specified in to the ...