如何通过Content-Type:application / octet-stream php将资源发送到API

时间:2018-02-09 15:32:55

标签: php curl binary

我正在尝试在php中重现此POST https://www.screencast.com/t/OUE1StfLfyP7,但我无法归档它正常工作,因为在下载图像后无法打开它

    $url = "https://internal-api-staging-lb.interact.io/v2/contacts/X/documents/fr_FR9.gif";

    $data = array('file' => '@'.realpath('https://www.viventura.de/images/icons/flags/fr_FR.gif'));

    // Initialize cURL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1 );
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/octet-stream", "authToken: XX"));
    // Set URL on which you want to post the Form and/or data
    curl_setopt($ch, CURLOPT_URL, $url);
    // Data+Files to be posted
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    // Pass TRUE or 1 if you want to wait for and catch the response against the request made
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // For Debug mode; shows up any error encountered during the operation
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    // Execute the request
    $response = curl_exec($ch);

我做错了什么有人可以帮我一把忙?非常感谢。

0 个答案:

没有答案