powershell - 尝试使用 power shell 将 zip 文件上传到 nexus,但失败了
问题描述
我对 power shell 脚本非常陌生,在将 zip 文件上传到 nexus 时遇到问题,下面是我用于上传的 power shell 脚本
$FilePath = "C:\Users\asd\SomeFile.zip";
$Uri = 'https://some.place.over.the.rainbow.com/api/v1/dataupdate';
$user = 'user_name'
$pass = 'abc123'
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
};
$fileBin = [IO.File]::ReadAllBytes($FilePath)
$enc = [System.Text.Encoding]::GetEncoding("iso-8859-1")
$fileEnc = $enc.GetString($fileBin)
$boundary = [System.Guid]::NewGuid().ToString()
$LF = "`r`n"; # and tried with $LF = "`n";
$bodyLines = (
"--$boundary",
"Content-Disposition: form-data; name=`"file`"$LF",
$fileEnc,
"--$boundary--$LF"
) -join $LF
Invoke-RestMethod -Uri $Uri -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -Headers $Headers -Body $bodyLines
它失败并出现以下错误
cannot send content-body with this verb-type
我正在使用 powershell 5.x 版
解决方案
推荐阅读
- javascript - 禁用右键单击 html5 音频元素
- nativescript - Nativescript 选项卡:想要路由到不是选项卡的模板/组件
- sql - Django - 如果另一列不同,则求和
- amazon-web-services - 确定和更新 AWS Lambda 上的 openssl 版本
- c - 为什么要使用函数指针?
- python - 第 3 行,在
从 app.forms 导入 LoginForm - javascript - Firebase JS SDK OAuth2 请求参数:access_type: 'offline'
- excel - 导入带有前导空单元格的 excel 删除逗号
- python - 显示语法错误:Jupyter Notebook 上打印语句的语法无效
- selenium - 用 selenium chromedriver 刮痧现在似乎要慢得多