Home > Backend Development > PHP Problem > What to do if PHP fails to send POST request

What to do if PHP fails to send POST request

藏色散人
Release: 2023-03-11 13:14:01
Original
4342 people have browsed it

Solution to PHP failure to send POST request: first check the error through "echo curl_error($ch);"; then set https trust when requesting.

What to do if PHP fails to send POST request

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?

What to do if PHP fails to send 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.
What to do if PHP fails to send POST request

<?php     // 相关参数
    $data = array(
        &#39;title&#39; => "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;
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template