【问题标题】:Curl HTTP Post Issue卷曲 HTTP 发布问题
【发布时间】:2018-10-27 12:41:10
【问题描述】:

它的 Postman HTTP Post 请求代码。

POST /upload.php HTTP/1.1
Host: 12.99.22.12
Cache-Control: no-cache
Postman-Token: 79b6cf45-9180-70e1-2136-8af2f8f67271
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="dosya"; filename="deneme--1.csv"
Content-Type: application/vnd.ms-excel


            ------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="yukle"

Yükle
------WebKitFormBoundary7MA4YWxkTrZu0gW--

我写了这段代码。是不是一样?

 $postfields = array("dosya" => "@$path","yukle"=>"Yükle","filename"=>"deneme--1.csv");
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
        //curl_setopt($ch, CURLOPT_HEADER , 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $sonuc=curl_exec($ch);
        curl_close($ch);

文件未上传。为什么 ? Http 代码有效,但 php 代码无效。我不知道为什么。我的错在哪里?

【问题讨论】:

标签: php curl post postman php-curl


【解决方案1】:

你需要创建文件上传

    // php version >= 5.5
if (function_exists('curl_file_create')) { 
    $file_post = curl_file_create($full_path_file);
} else { 
    $file_post = '@' . realpath($full_path_file);
}
$postfields = array("dosya" => $file_post,"yukle"=>"Yükle","filename"=>"filename");

【讨论】:

    猜你喜欢
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-24
    • 2016-02-07
    • 2011-03-01
    • 1970-01-01
    相关资源
    最近更新 更多