Wp_remote_post not posting data

You’re passing request params incorrectly.

Take a look at Codex page. You can find such example in there:

$response = wp_remote_post( $url, array(
  'method' => 'POST',
  'timeout' => 45,
  'redirection' => 5,
  'httpversion' => '1.0',
  'blocking' => true,
  'headers' => array(),
  'body' => array( 'username' => 'bob', 'password' => '1234xyz' ),
  'cookies' => array()
   )
);

So in your case it should look something like this:

$args = array(
    'method' => 'POST',
    'headers'  => array(
        'Content-type: application/x-www-form-urlencoded'
    ),
    'sslverify' => false,
    'body' => array(
        'api' => get_option('API_key'),
        'gw' => '1'
    )
);

$api_response = wp_remote_post('https://myurl.com/api', $args);

Leave a Comment