0

for some reason I got stuck with an simple Invoke-WebRequest. I need to send an XML-File to a website by Method "POST" and enc-Type "multipart/form-data". My code:

$SupraliftXML="C:\supralift.xml"
$Uri = 'https://www.supralift.com/servlet/EcutServlet?handler=BulkloadHandler&jfaction=0'
$Form = @{
    muddledPassword  = 'mypassword'
    userID   = 'myuserID'
    XMLfile  = Get-Item -Path $SupraliftXML
}
$Result = Invoke-RestMethod -AllowUnencryptedAuthentication -Uri $Uri -Method Post -Form $Form

I got an error that there is no parameter like "-form"

$Result = Invoke-WebRequest -Uri $Uri -Method Post -Form $Form + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Thank you for any help!

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Jan
  • 1
  • 2
  • 2
    The `-Form` Parameter was introduced in PS 6.1.0 . Make sure what Version you are using with `$host.Version`. Ref: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-6 - "This feature was added in PowerShell 6.1.0." – Paxz Nov 22 '18 at 12:34
  • Also take a look at https://stackoverflow.com/questions/38164723/uploading-file-to-http-via-powershell , this basically solves your problem. – Paxz Nov 22 '18 at 13:41

0 Answers0