文档

0006-00000102

更新时间:

问题描述

PostObject请求Content-Type参数不合法。

问题原因

您发起了PostObject请求,但是请求头中Content-type参数的值不符合接口要求。Content-Type字段要求格式为multipart/form-data; boundary={boundary}

问题示例

以下请求中Content-Type请求头取值为multipart/form-data;,缺少boundary={boundary}

POST / HTTP/1.1
Host: oss-example.oss-cn-hangzhou.aliyuncs.com
Content-Length: 6443500495
Date: Sat, 18 Feb 2023 05:17:02 GMT
Content-Type: multipart/form-data;
Host: example-bucket.oss-cn-hangzhou.aliyuncs.com
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="name"
big.img
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="key"
${filename}
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="policy"
eyJleHBpcmF0aW9uIjoiMjAyMy0wMi0xOFQxMzoxOTowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF1dfQ==
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="OSSAccessKeyId"
LTAI5tMw****
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="success_action_status"
200
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="signature"
miAoLVohS5*****WEXyC3wVecaQ=
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="file"; filename="big.img"
Content-Type: application/octet-stream
***
------WebKitFormBoundaryW0DET1iaBMeAOBg3--

解决方案

PostObject请求中请求头Content-type用于指定文件的类型和网页的编码,确定浏览器读取文件的形式和编码。Post操作提交表单编码必须为multipart/form-data,即Header中Content-Type为multipart/form-data;boundary=xxxxxx的形式。

boundary为边界字符串,是由表单随机生成的一个随机值,无需指定。如果通过SDK拼接表单,则SDK也会生成一个随机值。

相关文档