gpt4 book ai didi

php - curl 到 wp_remote_post 转换

转载 作者:搜寻专家 更新时间:2023-10-31 21:29:38 25 4
gpt4 key购买 nike

我想将它们转换成 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);

我几乎尝试过这个

$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' => '['.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 );

关于php - curl 到 wp_remote_post 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31398621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com