Articles of curl

Creating login session via CURL

Using the following code I experienced some problems: Login works but every link in the dashboard I will click will follow into the 404 not found page. It seems that there won’t be a working session created? $username=”admin”; $password=”admin”; $url=””; $cookie=”cookie.txt”; $postdata = “log=”. $username .”&pwd=”. $password .”&wp-submit=Log%20In&redirect_to=”. $url .”wp-admin/&testcookie=1″; $ch = curl_init(); curl_setopt ($ch, […]

On Plugin Activation, How Do I Check for Proper Transport Mechanism?

For a plugin that communicates with somewhere else, I hear we’re supposed to use wp_remote_post and wp_remote_get instead of PHP’s Curl library. Okay, but is there a fast and proper way on plugin execution to test for a blog’s PHP/host OS to have the proper transport mechanism installed? I mean, I could attempt a test […]

How can I use CURLOPT_USERPWD in wp_remote_post?

I’m trying to setup a proper cURL call in WordPress so am using wp_remote_post(). However, I’m having trouble authenticating the user via wp_remote_post(). Any idea how to convert the following to be used in wp_remote_post? curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_USERPWD, “$username:$password”); Full example of proper cURL basic auth is here.

Retrieving Google Plus share count with wp_remote_post

So I’ve spent most of my morning working on my website’s customized social share buttons. Reading out Twitter and Facebook shares were no problem, but Google Plus is a real challenge, as they don’t offer an easy-to-use GET API. I found a working technique using barebones CURL ( ). But previously, I’ve tried hard […]

wp_remote_get vs. file_get_contents vs. cURL?

I need to fetch the contents of a remote file. Which is better for performance – wp_remote_get, file_get_contents, or cURL? How exactly does wp_remote_get work? Can you suppress errors, ex. @wp_remote_get ? Thanks

HTTP request on localhost failing

I have a WordPress instance on my development box with the WP REST API plugin installed. I am attempting to create my own plugin to use wp_remote_get() to communicate with my own custom PHP application on the same box. I have set up my hosts file with the name of the custom PHP application. I […]

Passing .pem and .key files in cURL doesn't work in WordPress

I’m building a payment gateway plugin for woocommerce which requires sending an XML request via cURL, encrypted with private key. I’m using the following code: $xml_request ='<?xml version=”1.0″ encoding=”utf-8″?>’; $test_URL = ‘’; // Here is where I change the file paths $certfile = ‘/clientcert.pem’; $keyfile = ‘/clientkey.key’; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $test_URL ); […]

Re use authenticated HTTP connection or cUrl handle

We have a bespoke WordPress plugin, which adds a meta box to the edit post page. The plugin accesses data from a semi-private HTTP REST API. The connection is authenticated (DIGEST) and accessed regularly – every person writing a post will interact with it several times (usually in tight bursts) and there are > 100 […]

Creating a post with the REST API, curl and oauth returning 401 error

I’m trying to create a WordPress post using the REST API, OAuth, and cURL. However, I’m running into some trouble. I’m able to create a blank post (no title, slug, etc) using the following code: $header = array(buildAuthorizationHeader($oauth), ‘Expect:’); $options = array( CURLOPT_HTTPHEADER => $header, CURLOPT_ENCODING => “”, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_POST […]

Uploading media with the REST API

I am having trouble when uploading media to a WordPress site with the JSON REST API. With the following code I can upload the photos, but no info is assigned to them, not even the name – in fact the name automatically becomes the URL and filename (without the extension). $username = “ZX”; $password = […]