PowerShell equivalent for loading the cURL command file

I can send an HTTP POST text file to my server using the following cURL command:

curl -i -F file=@file.txt http://www.website.com/put_file

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

I have the following, but it does not work:

$url = http://www.website.com/put_file
$file = "c:\file.txt"
$wc = new-object System.Net.WebClient
$wc.UploadFile($url, $file.FullName)

it returns 0 and it does not load to the server

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

+5
source share
2 answers

I think it should be something like this:

$body = "file=$(get-content file.txt -raw)"
Invoke-RestMethod -uri http://www.websetite.com/put_file -method POST -body $body

: PowerShell V3. , -ContentType "application/x-www-form-urlencoded". Fiddler2 Inovke-RestMethod, irm. , . , , , multipart/form-data.

+6

, curl.exe Windows curl.

0

All Articles