Home > Article > Backend Development > What to do if PHP fails to send POST request
Solution to PHP failure to send POST request: first check the error through "echo curl_error($ch);"; then set https trust when requesting.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
Specific questions:
What should I do if PHP fails to send a POST request?
The POST request sent to Weibo's headline article advanced writing interface failed and no return data was received. The code is modified based on the demo provided by Weibo.
It is feasible if you use Python to send requests.
<?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;
How should the PHP code be modified?
Solution:
First use echo curl_error($ch); to see what the error is?
Then it may be the reason for https. When requesting, set https trust and do not check https.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if PHP fails to send POST request. For more information, please follow other related articles on the PHP Chinese website!