powershell invoke-restmethod multipart/form-data

后端 未结 6 593
不思量自难忘°
不思量自难忘° 2020-12-01 09:50

I\'m currently trying to upload a file to a Webserver by using a REST API. And as mentioned I\'m using PowerShell for this. With curl this is no problem. The call looks like

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 10:29

    With PowerShell Core this should work out of the box with the new -Form parameter.

    See: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7

    $Uri = 'https://api.contoso.com/v2/profile'
    $Form = @{
        firstName  = 'John'
        lastName   = 'Doe'
        email      = 'john.doe@contoso.com'
        avatar     = Get-Item -Path 'c:\Pictures\jdoe.png'
        birthday   = '1980-10-15'
        hobbies    = 'Hiking','Fishing','Jogging'
    }
    $Result = Invoke-RestMethod -Uri $Uri -Method Post -Form $Form
    

提交回复
热议问题