3
votes

I'm trying to convert this working request done in Cygwin to Powershell:

Cygwin (Working):

curl -k -u curl:Password -X PUT -F "file=$($_)" https://$($appliance)/wse/customblockpage/file/en

Powershell (not working):

Invoke-Webrequest -Uri "https://$($appliance)/wse/customblockpage/file/en" -Method Put -Infile "$homePath\$($_)" -Credential $cred

Here is the error I get:

Invoke-Webrequest : { "Error": "No file part in file", "Result": "Failure" } At line:1 char:1 + Invoke-Webrequest https://{IP Address Masked}/wse/customblockpage/file/en ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

1

1 Answers

0
votes

The { "Error": "No file part in file", "Result": "Failure" } is actually the error response from the web server and not a specific PowerShell error message.

In your cURL invocation, you are specifying form data with the -F flag, yet you don't appear to be doing the same in PowerShell.

In PowerShell, you can specify form data using the -Body flag like this:

Invoke-Webrequest -Uri "https://example.com/" -Method Put -Body @{ "file" = "hello.txt" }

If you need to send the actual content of the file, then you can use this as your -Body argument:

-Body @{ "file" = (Get-Content hello.txt) }