This works in php:
$postdata = http_build_query(
array(
'api' => get_option('API_key'),
'gw' => '1'
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$api_response = file_get_contents('https://myurl.com/api', false, $context);
However, this does not work in WordPress:
$args = array(
'method' => 'POST',
'headers' => 'Content-type: application/x-www-form-urlencoded',
'sslverify' => false,
'api' => get_option('API_key'),
'gw' => '1'
);
$api_response = wp_remote_post('https://myurl.com/api', $args);
It basicly should do the same, but wordpress somehow fails to send the POST data. I want to send the data to server and get the HTML response as $api_response
.