【发布时间】:2017-12-26 09:13:17
【问题描述】:
我必须将此 curl 转换为 wp_remote_post。
function post_api($url, $postfields) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
return $result;
}
$postfields = json_encode(array('redeemcode'=> $redeemcode));
$data = post_api("https://bitaps.com/api/get/redeemcode/info", $postfields);
我试过这个但是出错了..... Jason Decode 错误。
$data = wp_remote_post( "https://bitaps.com/api/get/redeemcode/info", array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => $postfields,
'cookies' => array()
)
);
【问题讨论】: