我正在尝试使用PowerShell 3和4中的Invoke-RestMethod cmdlet,使用REST API的multipart/form-data上载来上传大型二进制文件.这是一个有关如何在PowerShell中执行我想要执行的操作的cURL示例:
curl -i -k -H "accept: application/json" -H "content-type: multipart/form-data" -H "accept-language: en-us" -H "auth: tokenid" -F file="@Z:\large_binary_file.bin" -X POST "https://server/rest/uri2"
Run Code Online (Sandbox Code Playgroud)
我很想看到一个关于如何使用Invoke-RestMethod来POST多部分/表单数据的工作示例.我在PowerShell团队发现了一篇博文,展示了如何使用Invoke-RestMethod上传到OneDrive(又名SkyDrive),但效果不佳.如果可能的话,我也想避免使用System.Net.WebClient.我还在Stackoverflow上找到了另一个线程,但它确实没有多大帮助.
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
$server = "https://server"
uri = "/rest/uri1"
$headers = @{"accept" = "application/json"; "content-type" = "application/json";"accept-language" = "en-us"}
$body = @{"userName" = "administrator"; "password" = "password"}
$method = "POST"
#Get Session ID
$resp = Invoke-RestMethod -Method $method -Headers $headers -Uri ($server+$uri) -body (convertto-json …Run Code Online (Sandbox Code Playgroud) 我有一个安装脚本,允许用户指定他们想要安装我的应用程序的位置。它以[Code]块内的 Pascal 脚本的形式出现。
var
SelectUsersPage: TInputOptionWizardPage;
IsUpgrade : Boolean;
UpgradePage: TOutputMsgWizardPage;
procedure InitializeWizard();
var
AlreadyInstalledPath: String;
begin
{ Determine if it is an upgrade... }
{ Read from registry to know if this is a fresh install or an upgrade }
if RegQueryStringValue(HKLM, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppId}_is1', 'Inno Setup: App Path', AlreadyInstalledPath) then
begin
{ So, this is an upgrade set target directory as installed before }
WizardForm.DirEdit.Text := AlreadyInstalledPath;
{ and skip SelectUsersPage }
IsUpgrade := True;
{ Create a …Run Code Online (Sandbox Code Playgroud)