调用RestMethod到Nexus多部分/表单数据时出现Powershell错误

调用RestMethod到Nexus多部分/表单数据时出现Powershell错误,rest,powershell,httpwebrequest,multipartform-data,nexus,Rest,Powershell,Httpwebrequest,Multipartform Data,Nexus,我正在尝试执行一个到Nexus3.10的post请求来上传我的工件。这是代码 # the uri, get the zip file, and encode it $Uri = 'http://nexus.com/service/rest/beta/components?repository=myRepo'; $encoding = "ISO-8859-1" $zipFile = [System.IO.File]::ReadAllBytes('C:\file.zip') $enc = [Sys

我正在尝试执行一个到Nexus3.10的post请求来上传我的工件。这是代码

# the uri, get the zip file, and encode it
$Uri = 'http://nexus.com/service/rest/beta/components?repository=myRepo';
$encoding = "ISO-8859-1"

$zipFile = [System.IO.File]::ReadAllBytes('C:\file.zip')
$enc = [System.Text.Encoding]::GetEncoding($encoding)
$fileEncoded = $enc.GetString($zipFile)

# generate a random boundary
$boundary = [System.Guid]::NewGuid().ToString()

# here we make the multipart body for Nexus
$bodyLines = (
    "--$boundary",
    "Content-Disposition: form-data; name=`"maven2.groupId`"$LF",
    "group.id",
    "--$boundary",
    "Content-Disposition: form-data; name=`"maven2.artifactId`"$LF",
    "artifact.id",
    "--$boundary",
    "Content-Disposition: form-data; name=`"maven2.version`"$LF",
    "2.1",
     "--$boundary",
    "Content-Disposition: form-data; name=`"maven2.generate-pom`"$LF",
    "true",
    "--$boundary",
    "Content-Disposition: form-data; name=`"maven2.packaging`"$LF",
    "zip",
    "--$boundary",
    "Content-Disposition: form-data; name=`"maven2.asset1`"; filename=`"file.zip`"",
    "Content-Type: application/zip$LF",
    $fileEncoded,
    "--$boundary",
    "Content-Disposition: form-data; name=`"maven2.asset1.extension`"$LF",
    "zip",
    "--$boundary--"
    ) -join $LF

Invoke-RestMethod -Uri $uri -Method POST -ContentType "multipart/form-data;boundary=`"$boundary`"" -Body $bodyLines
但是,我得到的错误如下:

java.lang.IllegalArgumentException:在当前数据库中找不到类“selector\u selector”
来自
调用调用调用RestMethod

我通过chrome浏览器请求验证,我知道多部分表的格式正确。我做错了什么

下面是当我的回声消失时发生的情况

--abe15049-dd30-48f4-ace4-d9ba245e0546
Content-Disposition: form-data; name="maven2.groupId"

group.id
--abe15049-dd30-48f4-ace4-d9ba245e0546
Content-Disposition: form-data; name="maven2.artifactId"

artifact.id
--abe15049-dd30-48f4-ace4-d9ba245e0546
Content-Disposition: form-data; name="maven2.version"

2.1
--abe15049-dd30-48f4-ace4-d9ba245e0546
Content-Disposition: form-data; name="maven2.generate-pom"

true
--abe15049-dd30-48f4-ace4-d9ba245e0546
Content-Disposition: form-data; name="maven2.packaging"

zip
--abe15049-dd30-48f4-ace4-d9ba245e0546
Content-Disposition: form-data; name="maven2.asset1"; filename="file.zip"
Content-Type: application/zip

[a bunch of binary data]    
--abe15049-dd30-48f4-ace4-d9ba245e0546
Content-Disposition: form-data; name="maven2.asset1.extension"

zip
--abe15049-dd30-48f4-ace4-d9ba245e0546--

我会尝试使用Write Host查看$bodyLines字符串的确切外观。我怀疑你有引用的问题。我已经补充了这一点,但没有发现任何不同之处