1

I don't want cURL in my WordPress plugin

Hi, cURL is not safe to use on WordPress site. And sometime, cURL has been disable on customer hosting.

And i decided to use wp_remote_post to send file for my plugin

Here my code :

$service = URL SERVICE ;

 $headers = array(
            'accept'       => 'application/json', // The API returns JSON
            'content-type' => 'application/binary', // Set content type to binary
        );


$data     = array(
                'headers'  => $headers,
                'body'     => file_get_contents($image_file),
            );
$response = wp_remote_post($service, $data);

But on server, i cannot received file from wp_remote_post. Please help me fix this issue ? How i can config to send file from wp_remote_post same as CURLFile ?

0

I found an solution for this issue, i using wp_remote_post to send binary of file to server.

When processing data received on server, i use this code to get data of file

$file = file_get_contents('php://input');

And i write it to temp file

$temp   = tmpfile();
fwrite($temp, $file);
$metadata = stream_get_meta_data($temp);

Do you have any other solution ? Please discuss with me to find best answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.