Inconsistencies between wp_remote_post and cURL

As discovered above, headers need to be (seems so obvious now) key-value pairs, as opposed to an array of json-style key-values: $headers = array(); $headers[‘Content-Type’] = ‘application/json’; $headers[‘Api-Key’] = ‘{myapikey}’; $headers[‘Siteid’] = ‘99999’; And the body needs to be json so either: ‘body’ => “{\n \”Username\”: \”Siteowner\”,\n \”Password\”: \”apitest1234\”\n}” or ‘body’ => json_encode(array( ‘Username’ => … Read more

Call external API in wordpress based on user input

s is a reserved keyword, you cannot reuse the URL parameters and query variables used by WordPress itself. This issue is unrelated to the API request code. Because your form has an input with the name s, the request is interpreted as a search request. As no posts were found in the WordPress search, you … Read more

cURL request to plugin repository fails 403

Thanks to the WordPress forums someone answered that this only works via PHP if you set the UserAgent to a browser. $ua=”Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13″; curl_setopt( $cd, CURLOPT_USERAGENT, $ua);

Difference between `curl -I` and `curl -X HEAD`

It seems the difference has to do with the Content-Length header and how it is treated by both commands. But before going into that, curl -X HEAD does not give any output because, by default, curl does not print headers if switch -i is not provided (not needed on -I though). In any case, curl … Read more

Download file using cURL into wp-includes/uploads

There is special wp_upload_bits() function to upload the content to the ‘uploads’ directory. Also, there is no such directory as /wp-includes/upload/. The code was not tested! <?php $video_id = ‘xxxxxxxxxxxxx’; $thumbnail_types = array( ‘0’, ‘1’, ‘2’, ‘3’, ‘default’, ‘sddefault’, ‘mqdefault’, ‘hqdefault’, ‘maxresdefault’, ); foreach( $thumbnail_types as $type ) { $file_name = $type . ‘.jpg’; $youtube_thumb_url=”http://img.youtube.com/vi/” … Read more

How to send file by wp_remote_post?

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 … Read more