簡體   English   中英

Linux cURL與PHP cURL - POST請求

[英]Linux cURL vs PHP cURL - POST Request

我必須使用HTTPS上傳ZIP文件,這只能通過Linux cURL命令工作。 我不明白我在PHP cURL請求中缺少什么...

Linux cURL [工作]:

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 [不工作]:

$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。” 我也注意到Content-Length不一樣......為什么?

提前感謝您的建議!

擺脫界限:

  'Content-Type: text/plain'

您正在為整個郵件設置內容類型,而不是正確格式化POST數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM