Curl HTTP Post Issue - PullRequest
       15

Curl HTTP Post Issue

0 голосов
/ 17 мая 2018

Код запроса почты Postman HTTP.

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 не работает.Я не знаю почему.где моя ошибка?

1 Ответ

0 голосов
/ 17 мая 2018

Вам нужно создать файл для загрузки

    // 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");
...