powershell中用于上载apk文件的curl等效命令是什么?
我正在尝试使用Perfecto执行CI/CD,因此我正在尝试在我的竹子构建完成后将一个文件上载到Perfecto 当我们使用Linux服务器时,我正在尝试使用下面的cURL命令powershell中用于上载apk文件的curl等效命令是什么?,powershell,Powershell,我正在尝试使用Perfecto执行CI/CD,因此我正在尝试在我的竹子构建完成后将一个文件上载到Perfecto 当我们使用Linux服务器时,我正在尝试使用下面的cURL命令 curl -X POST --upload-file test.apk 'https://****.perfectomobile.com/services/repositories/media/PRIVATE:test.apk?operation=upload&user=<email>&pas
curl -X POST --upload-file test.apk 'https://****.perfectomobile.com/services/repositories/media/PRIVATE:test.apk?operation=upload&user=<email>&password=<password>&overwrite=true'
curl-X POST--upload file test.apk'https://**.perfectomobile.com/services/repositories/media/PRIVATE:test.apk?operation=upload&user=&password=&overwrite=true'
现在,我们的服务器已更改为Windows,因此我需要一个powershell脚本,我可以将其用作竹子中的内联脚本
您能告诉我什么是Powershell for windows中的等效脚本吗
非常感谢
# Gather your information.
$email = "myEmail@website.com";
$password = "powershellR0cks!";
$subDomain = "****";
$url = "https://$subDomain.perfectomobile.com/services/repositories/media/PRIVATE:test.apk?operation=upload&user=$email&password=$password&overwrite=true";
$filePath = ".\test.apk";
# Make the request.
$response = Invoke-WebRequest -Uri $URL -Method Post -InFile $filePath -ContentType "application/octet-stream";
# Check for success.
if (-not ($response.StatusCode -eq 200)) {
throw "There was an error uploading the APK manifest.";
}
您可能想检查-ContentType
的值,但我认为这是正确的。如果不想,您不一定需要包含该方案(HTTPS),PowerShell中的分号是可选的,但如果需要,您可以包含它们
$response
变量是一个HtmlWebResponseObject
,它包含响应的内容、状态代码和一系列其他有用的信息。您可以通过运行$response | Get Member
来检查对象上可用的属性和方法
最后,Invoke-WebRequest
cmdlet还有其他可能对您有用的参数,例如-Credential
,-Headers
,等等
作为旁注,如果您运行
Get Alias-Name“curl”
,您可以看到,只要在PowerShell中使用curl
,您实际上就是在调用Invoke WebRequest
。如果需要,您可以使用curl
别名,但是在自动化中使用别名通常不是一个好主意,因为它们可以被修改或删除。看看我又添加了一行代码来实现它。[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12