aliyun / aliyun-oss-csharp-sdk

Aliyun OSS SDK for C#
MIT License
379 stars 204 forks source link

你好,我使用httpclient 请求post policy一直提示MethodNotAllowed #121

Closed qzwzqty closed 1 year ago

qzwzqty commented 3 years ago

生成的表单:

POST https://xxxxx.aliyuncs.com/ HTTP/1.1
Host: zhjx-test.oss-cn-beijing.aliyuncs.com
traceparent: 00-0898eb2e870e6d4abc91d45a6b502e9f-71bfda7bcf508040-00
ContentType: multipart/form-data, boundary=9431149156168
Content-Length: 12068

--9431149156168
Content-Disposition: form-data; name="OssAccessKeyId"

Lxxxxxxxxa
--9431149156168
Content-Disposition: form-data; name="key"

xxxx/xxxx/test.jpg
--9431149156168
Content-Disposition: form-data; name="policy"

eyJleHBxxxxxxxJ9XX0=
--9431149156168
Content-Disposition: form-data; name="signature"

Hxxxxxx=
--9431149156168
Content-Disposition: form-data; name="success_action_status"

201
--9431149156168
Content-Type: image/jpeg
Content-Disposition: form-data; name="file"; filename="test.jpg"

(data)
--9431149156168--

返回的错误:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
  <Code>MethodNotAllowed</Code>
  <Message>The specified method is not allowed against this resource.</Message>
  <RequestId>6041BAB893E78F3434415D2E</RequestId>
  <HostId>zhjx-test.oss-cn-beijing.aliyuncs.com</HostId>
  <Method>POST</Method>
  <ResourceType>Bucket</ResourceType>
</Error>

谢谢。

StringKe commented 1 year ago

遇到一样的错误,是 ContentType: multipart/form-data, boundary=9431149156168 写错了

正常是 ContentType: multipart/form-data; boundary=9431149156168

另外也不支持 Content-Type: multipart/form-data; charset=utf-8; boundary=X_PAW_BOUNDARY 设置 charset

qzwzqty commented 1 year ago

@StringKe 多谢多谢,我试试看

qzwzqty commented 1 year ago

@StringKe 大佬,你好,我现在遇到另一个问题了,大佬有空帮我看看,谢了。

<Error>
  <Code>MalformedPOSTRequest</Code>
  <Message>The body of your POST request is not well-formed multipart/form-data</Message>
  <RequestId>64C882A48C0B5C37379B15EB</RequestId>
  <HostId>zhjx-test.oss-cn-beijing.aliyuncs.com</HostId>
  <EC>0006-00000109</EC>
</Error>

表单:

POST https://xxxx.oss-cn-beijing.aliyuncs.com/ HTTP/1.1
Host: zhjx-test.oss-cn-beijing.aliyuncs.com
Accept: application/json
Content-Type: multipart/form-data; boundary="9431149156168"
Content-Length: 151432

--9431149156168
Content-Disposition: form-data; name="success_action_status"

201
--9431149156168
Content-Disposition: form-data; name="OssAccessKeyId"

LTxxxx
--9431149156168
Content-Disposition: form-data; name="key"

xxxx/xxxx
--9431149156168
Content-Disposition: form-data; name="policy"

xxxx
--9431149156168
Content-Disposition: form-data; name="signature"

xxxx
--9431149156168
Content-Type: image/jpge
Content-Disposition: form-data; name="file"; filename=testfilename.jpg; filename*=utf-8''testfilename.jpg
qzwzqty commented 1 year ago

卧槽,我知道怎么回事了,Content-Type: image/jpge 要去掉,Content-Disposition: form-data; name="file"; filename=testfilename.jpg; filename*=utf-8''testfilename.jpg 改为:Content-Disposition: form-data; name="file"; filename="testfilename.jpg"