wp_remote_post wp_remote_request file upload
<?php | |
// wp_remote_request way | |
$file = @fopen( 'path/to/file.txt', 'r' ); | |
$file_size = filesize( 'path/to/file.txt' ); | |
$file_data = fread( $file, $file_size ); | |
$args = array( | |
'method' => 'POST' | |
'headers' => array( | |
'accept' => 'application/json', // The API returns JSON | |
'content-type' => 'application/binary', // Set content type to binary | |
), | |
'body' => $file_data | |
); | |
$result = wp_remote_request( 'https://domain.com/api/v2/uploads.json?filename=myfile.dat' $args ); | |
// wp_remote_post way | |
$file = @fopen( 'path/to/file.txt', 'r' ); | |
$file_size = filesize( 'path/to/file.txt' ); | |
$file_data = fread( $file, $file_size ); | |
$args = array( | |
'headers' => array( | |
'accept' => 'application/json', // The API returns JSON | |
'content-type' => 'application/binary', // Set content type to binary | |
), | |
'body' => $file_data | |
); | |
$result = wp_remote_post( 'https://domain.com/api/v2/uploads.json?filename=myfile.dat' $args ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment