使用PowerShell Invoke-RestMethod将Zip上传到Phonegap

时间:2013-06-19 13:18:53

标签: powershell cordova

我尝试编写PowerShell脚本,只需一键解决方案即可上传和构建我的移动应用程序。我已经使用cURL成功完成了此操作,但尝试使用本机PowerShell命令。在cURL中,我可以使用-F(--form)参数并传递zip文件(例如-F file = @ C:... \ www.zip)。我无法弄清楚如何使用PowerShell实现同样的功能。我正在尝试使用Invoke-RestMethod,但不确定这是否正确。这是PhoneGap API的链接:  https://build.phonegap.com/docs/write_api

任何帮助都会非常感激!

2 个答案:

答案 0 :(得分:3)

Invoke-RestMethod -Uri https://build.phonegap.com/api/v1/apps/:id -Headers @{Authorization='Basic username-and-password-in-base64'} -Method Put -InFile "www.zip"

username-and-password-in-base64是您的Adobe / PhoneGap Build用户名和密码,组合成一个字符串“username:password”,并使用Base64(http://www.base64decode.org/)进行编码。

:网址中的ID是您在phonegap内建的应用ID。

答案 1 :(得分:0)

尝试这样的事情:

$pathToZip = "bin/phonegap.zip"
$user = "user"
$pass = "password"

## convert to secure password since we can't use get-credential in non interactive mode
$securepass = ConvertTo-SecureString $pass -AsPlainText -Force

## create a PSCredential object
$credential = New-Object System.Management.Automation.PSCredential($user, $securepass)

$appId = "12345"
$url = "https://build.phonegap.com/api/v1/apps/" + $appId;

Write-Host $url

Invoke-RestMethod -Uri $url -Credential $credential -Method Put -InFile $pathToZip