PHP发送POST请求失败的解决办法:首先通过“echo curl_error($ch);”查看错误;然后在请求的时候设置https信任即可。

本文操作环境:Windows7系统、PHP7.1版,DELL G3电脑
具体问题:
PHP发送POST请求失败怎么办?

立即学习“PHP免费学习笔记(深入)”;
向微博的头条文章高级写入接口发送POST请求失败,收不到任何返回数据。代码是基于微博提供的demo修改的。
如果用Python发送请求,是可行的。
<?php
// 相关参数
$data = array(
'title' => "Test_Title",
'content' => rawurlencode("Test_Content"),
'cover' => "https://api.xygeng.cn/bing/1920.php",
'summary' => "Test_Summary",
'text' => "Test_Content",
'access_token' => ""
);
// 发送POST请求
$ch = curl_init ();
$url = "https://api.weibo.com/proxy/article/publish.json";
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data);
$ret = curl_exec ( $ch );
curl_close ( $ch );
echo $ret;PHP代码应该如何修改呢?
解决办法:
首先通过echo curl_error($ch);看看错误是什么?
然后可能是https的原因,请求的时候设置https信任,不检查https。
推荐学习:《PHP视频教程》
以上就是PHP发送POST请求失败怎么办的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号