因此,我有一个curl命令,它可以很好地工作。但是,当我尝试在Resty中实现它时,我得到了一个错误: 405 (不允许使用方法)。现在,不应该太认真地对待这个错误代码。我只是在暗示我做错了什么。
像冠军一样工作的curl命令执行以下操作:
christianb@christianb-mac hashicorp % curl -vn --location --request PUT 'http://localhost:8081/artifactory/example-repo-local/crash.zip' \
--header 'Content-Type: application/zip' \
--data-binary '@./samples/crash.zip'
* Trying 127.0.0.1:8081...
* Connected to localhost (127.0.0.1) port 8081 (#0)
* Server auth using Basic with user 'admin'
> PUT /artifactory/example-repo-local/crash.zip HTTP/1.1
> Host: localhost:8081
> Authorization: Basic xxx=
> User-Agent: curl/7.78.0
> Accept: */*
> Content-Type: application/zip
> Content-Length: 0
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 201
< X-JFrog-Version: Artifactory/7.24.3 72403900
< X-Artifactory-Id: 65b0c15e32af425b:-53411fa9:17be4f9b6e8:-8000
< X-Artifactory-Node-Id: cb4b887aed9e
< Location: http://localhost:8081/artifactory/example-repo-local/crash.zip
< X-Checksum-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
< Content-Type: application/vnd.org.jfrog.artifactory.storage.ItemCreated+json;charset=ISO-8859-1
< Transfer-Encoding: chunked
< Date: Wed, 15 Sep 2021 21:22:56 GMT
<
christianb@christianb-mac hashicorp % resty调用看起来是这样的:
PUT /artifactory/example-local-repo/crash.zip HTTP/1.1
Host: 127.0.0.1
User-Agent: jfrog/terraform-provider-artifactory:2.3.1
Content-Length: 4007
Accept: */*
Authorization: Basic cccxxx=
Content-Type: multipart/form-data; boundary=a8cddfc21bc1ecdf09e0c82e2e0ea2ac7627c4cbfeae3e51ed9e68987a99
Accept-Encoding: gzip
--a8cddfc21bc1ecdf09e0c82e2e0ea2ac7627c4cbfeae3e51ed9e68987a99
Content-Disposition: form-data; name="crash.zip"; filename="../../samples/crash.zip"
Content-Type: application/zip
...
HTTP/1.1 405
X-JFrog-Version: Artifactory/7.24.3 72403900
X-Artifactory-Id: 65b0c15e32af425b:-53411fa9:17be4f9b6e8:-8000
X-Artifactory-Node-Id: cb4b887aed9e
Allow: OPTIONS, GET, HEAD, POST
Content-Type: application/json;charset=ISO-8859-1
Content-Length: 65
Date: Wed, 15 Sep 2021 21:41:07 GMT
{
"errors" : [ {
"status" : 405,
"message" : ""
} ]
}所以,很明显,resty将此视为多部分上传,这是错误的。
有人知道这个curl命令的等效resty调用吗?
我试过了:
uri := "/artifactory/" + remotePath
reader, err := os.Open(localPath)
if err != nil {
return err
}
_, err = client.R().SetBody(reader).
SetHeader("Content-Type", contentType).Put(uri)和
_, err = client.R().SetFileReader(filepath.Base(localPath), localPath, reader).
SetHeader("Content-Type", contentType).Put(uri)和
uri := "/artifactory/" + remotePath
_, err := client.R().SetFile(filepath.Base(localPath),localPath).
SetHeader("Content-Type", contentType).Put(uri)都不起作用。
发布于 2021-09-16 08:37:06
SetFileReader和SetFile都是用于分块上传的。
使用SetBody函数是正确的,但我认为您需要先读入文件内容,然后将字节传递给SetBody
uri := "/artifactory/" + remotePath
data, err := os.ReadFile(localPath)
if err != nil {
return err
}
_, err = client.R().SetBody(data).
SetHeader("Content-Type", contentType).Put(uri)https://stackoverflow.com/questions/69200168
复制相似问题