powershell invoke-restmethod multipart/form-data

后端 未结 6 600
不思量自难忘°
不思量自难忘° 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:27

    It should be pretty straight forward. Taking from this answer:

    $Uri = 'https://server/api/';
    $Headers = @{'Auth_token'=$AUTH_TOKEN};
    $FileContent = [IO.File]::ReadAllText('C:\test\test.test');
    $Fields = @{'appInfo'='{"name": "test","description": "test"}';'uploadFile'=$FileContent};
    
    Invoke-RestMethod -Uri $Uri -ContentType 'multipart/form-data' -Method Post -Headers $Headers -Body $Fields;
    

    You may want to use [IO.File]::ReadAllBytes() if the file isn't a text file.

    This also may not work well if you're uploading a huge file.

提交回复
热议问题