我必须使用HTTPS上传ZIP文件,这只能通过Linux cURL命令工作 . 我不明白我在PHP cURL请求中缺少什么...
Linux cURL [working]:
curl -v -x http://api.test.sandbox.mobile.de:8080 -u USER:PASS -X POST --data-binary @502.zip https://services.mobile.de/upload-api/upload/502.zip
响应:
POST /upload-api/upload/502.zip HTTP/1.1
User-Agent: curl/7.38.0
Host: services.mobile.de
Accept: */*
Content-Length: 6026
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue
HTTP/1.1 100 Continue } [data not shown]
HTTP/1.1 201 Created
Date: Tue, 06 Dec 2016 12:40:41 GMT
Content-Type: text/html;charset=utf-8
Vary: Accept-Encoding
Transfer-Encoding: chunked
PHP cURL [not working]:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic '. base64_encode("USER:PASS"),
'Content-Type: text/plain'
));
curl_setopt($ch,CURLOPT_PROXY, 'api.test.sandbox.mobile.de:8080');
curl_setopt($ch,CURLOPT_URL, 'https://services.mobile.de/upload-api/upload/502.zip');
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, [ 'file' => new CURLFile('502.zip') ]);
curl_setopt($ch,CURLOPT_VERBOSE, 1);
$result = curl_exec($ch);
curl_close($ch);
响应:
POST /upload-api/upload/502.zip HTTP/1.1
Host: services.mobile.de
Accept: */*
Content-Length: 6225
Expect: 100-continue
Content-Type: text/plain; boundary=------------------------835f6ea7 5f783449
HTTP/1.1 100 Continue
HTTP/1.1 201 Created
Date: Tue, 06 Dec 2016 13:36:21 GMT
Content-Type: text/html;charset=utf-8
Vary: Accept-Encoding
Transfer-Encoding: chunked
在现场文档中写道:“上传文件必须作为HTTP-Payload发送,并且采用二进制格式,不支持Multipart和Encoding . ”我也注意到内容长度不一样......为什么?
提前感谢您的建议!
1 回答
摆脱界限:
您正在为整个邮件设置内容类型,而不是正确格式化POST数据 .