PowerShell equivalent for cURL command uploading file


I am able to send HTTP POST a text file to my server using the following cURL command:

The server is expecting a file from $_FILES[‘file’].

I have the following so far but it is not working:

it returns 0, and it did not upload to the server

How can I send the file as $_FILES[‘file’]? Also, how can I see the response from the server?


I think it should be something like this:

Note: this does require PowerShell V3. Also, you might need to specify the -ContentType parameter as "application/x-www-form-urlencoded". I recommend getting Fiddler2 and use it to inspect the request in both the curl and Inovke-RestMethod cases to help get the irm parameters correct. This is assuming the file contents are fairly small and non-binary. If not, you probably need to go to content type multipart/form-data.


PowerShell equivalent for cURL command uploading file by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply