示例代码:
$text = "有人在您的博客发表了评论";
$desp = "**".$comment['author']."** 在 [「".$post->title."」](".$post->permalink." \"".$post->title."\") 中说到: \n\n > ".$comment['text'];
$postdata = http_build_query(
array(
'text' => $text,
'desp' => $desp
)
);
$opts = array('http' =>array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://www.iyuu.cn/'.$sckey.'.send', false, $context);
return $comment;
以上这段代码,获取不到内容,提交会失败。
解决方法
添加以下参数就可以了
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
)
完整代码:
$text = "有人在您的博客发表了评论";
$desp = "**".$comment['author']."** 在 [「".$post->title."」](".$post->permalink." \"".$post->title."\") 中说到: \n\n > ".$comment['text'];
$postdata = http_build_query(
array(
'text' => $text,
'desp' => $desp
)
);
$opts = array('http' =>array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
),
// 解决SSL证书验证失败的问题
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://www.iyuu.cn/'.$sckey.'.send', false, $context);
return $comment;
版权属于:大卫科技Blog
本文链接:https://www.iyuu.cn/archives/206/
转载时须注明出处