【发布时间】:2015-03-11 05:22:59
【问题描述】:
所以我的问题是直到现在我在我的一个 wordpress 插件 cURL 中使用了 POST 请求,但现在我需要使用 wp_remote_post()。
wp_remote_post 看起来很简单,但我无法让它工作。所以我的问题是:有人可以告诉我如何将以下cURL 转移到wp_remote_post 吗?
卷曲:
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields ));
$result = curl_exec($ch);
curl_close($ch);
我的 wp_remote_post 版本
$result = wp_remote_post($url, array(
'method' => 'POST',
'headers' => $headers,
'body' => json_encode($fields) )
);
我收到wp_remote_post 的 401 错误,因为授权无效。
【问题讨论】: