这在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);
但是,这在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);
它基本上也应该这样做,但wordpress无法发送POST数据。我想将数据发送到服务器并获得HTML响应,如下所示$api_response
.