php - Curl to wp_remote_post convert -
i convert these wp_remote_post()
$curl = curl_init(); curl_setopt($curl, curlopt_url, "https://clients6.google.com/rpc"); curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_ssl_verifypeer, false); curl_setopt($curl, curlopt_postfields, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"'.rawurldecode($this->url).'","source":"widget","userid":"@viewer","groupid":"@self"},"jsonrpc":"2.0","key":"p","apiversion":"v1"}]'); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_httpheader, array('content-type: application/json')); $curl_results = curl_exec ($curl); curl_close ($curl); $json = json_decode($curl_results, true);
i tried this
$params = array( 'method' => 'post', 'timeout' => 45, 'blocking' => true, 'headers' => array( 'content-type' => 'application/json' ), 'body' => array( 'method' => 'pos.plusones.get', 'id' => 'p', 'params'=> array ( 'nolog' => true, 'id' => rawurldecode($url), 'source' => 'widget', 'userid' => '@viewer', 'groupid' => '@self', ), 'jsonrpc' => '2.0', 'key' => 'p', 'apiversion' => 'v1', ), ); $connection = wp_remote_post('https://clients6.google.com/rpc', $params);
but there error message - "unable parse json"
please help
thank you
this works
$params = array( 'method' => 'post', 'timeout' => 45, 'blocking' => true, 'headers' => array( 'content-type' => 'application/json' ), 'body' => '['.json_encode( array( 'method' => 'pos.plusones.get', 'id' => 'p', 'params' => array( 'nolog' => true, 'id' => rawurldecode( $url ), 'source' => 'widget', 'userid' => '@viewer', 'groupid' => '@self', ), 'jsonrpc' => '2.0', 'key' => 'p', 'apiversion' => 'v1', ) ).']' ); $connection = wp_remote_post( 'https://clients6.google.com/rpc', $params );
Comments
Post a Comment