Php 卷曲到wp_远程_后转换
我想把这些转换成wp_remote_post() 我差点就试过了Php 卷曲到wp_远程_后转换,php,wordpress,curl,Php,Wordpress,Curl,我想把这些转换成wp_remote_post() 我差点就试过了 $params = array( 'method' => 'POST', 'timeout' => 45, 'blocking' => true, 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => array( 'method'
$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);
但是有这样一条错误消息——“无法解析json”
请帮忙
谢谢注意到一些不一致之处。不确定语法是否抛出错误,但可能修复解析
$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'
)
);
这很有效
$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 );
$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 );