cURL / wp_remote_post: won’t work in wordpress plugin

I’m working on a wordpress plugin, which pull data from another site via a cURL post call. I’ve tested the same code in i wordpress plugin and outsite of wordpress.

Outsite of wordpress the script works fine, but inside a wordpress plugin, the script just wont work:

Read More

WordPress plugin:

$handle = curl_init();
curl_setopt($handle, CURLOPT_URL,             $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER,  true);
curl_setopt($handle, CURLOPT_POST,            true );
curl_setopt($handle, CURLOPT_FOLLOWLOCATION,  true );
curl_setopt($handle, CURLOPT_POSTFIELDS,      array('postfield' => 'postfieldcontent'));

$result = curl_exec($handle);

Main site:

mysql_query("INSERT INTO table (q, w, e, r, t, y, u) VALUES ('', '".$_POST[postfield]."', '', '', '', '', '')");

I’ve removed all database security for debugging purpose. I have also tried the wp_remote_post function, that doesn’t work either. I’ve even triede the the wp_remote_get function, but i can access the get variable:

$result = wp_remote_get( 'http://qwerty.dk/folder/filename.php?getfield=qwertrert' );

I’ve given up – please help 🙂

Best regards
Kim

Related posts

Leave a Reply

1 comment

  1. You will need to enable cURL in your php.ini file. See #1347146

    wp_remote_post() uses a class called WP_Http that in turn can use one of three transport classes (see file class-http.php function _get_first_available_transport).

    POST method will work with class WP_Http_Curl, but will not work with class WP_Http_Streams (the cURL fallback).

    The alternative is to use wp_remote_get()