Invoke-RestMethod到Nexus multipart / form-data的Powershell错误

时间:2018-04-17 17:22:31

标签: rest powershell httpwebrequest multipartform-data nexus

我正在尝试向Nexus 3.10发送帖子请求以上传我的工件。这是代码。

# 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: Class 'selector_selector' not found in current database来电的

Invoke-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--

0 个答案:

没有答案