PHP curl等价物

时间:2014-01-23 15:37:33

标签: php curl

如何在PHP中发布此内容?

curl -i -H "Content-Type: text/csv" -X POST --data-binary @test.csv blah/_/csvImport

这是我到目前为止所拥有的

$url = "http://blah/_/csvImport";
$file = "test.csv";

$request = curl_init();
// send a file
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_HTTPHEADER, array("Content-Type: text/csv"));
curl_setopt(
    $request,
    CURLOPT_POSTFIELDS,
    array(
      'data' => '@' . realpath($file)
    ));


curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($request);

// close the session
curl_close($request);

1 个答案:

答案 0 :(得分:1)

这是缺少的选项:

curl_setopt($request, CURLOPT_BINARYTRANSFER, true);

CURLOPT_BINARYTRANSFER用于-data-binary