PHP uses curl to request an interface of post, but no data is received there.

this is the curl method of post that I encapsulated

  
    static function PostCurl($uri, $params = array())
    {
        $url = self::CURL_URI . $uri;
        $params["pcs"] = 3;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);//header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        $output = curl_exec($ch);
        curl_close($ch);     
        return json_decode($output,true);
    }
Mar.18,2021

try json format and array format for your parameters.

not yet, it may be a coding problem.


personally, I think his side can check the nginx log and php execution log. In addition, you should also check the nginx log and PHP execution log.


`
curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query ($params));
`
$headers = curl_getinfo ($ch, CURLINFO_HEADER_OUT)); there is a difference between printing headers with or without http_build_query ().


function curls($url, $params = false, $ispost = 1, $https = 0)
{
    $httpInfo = array();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    if ($https) {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // SSL
    }
    if ($ispost) {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_setopt($ch, CURLOPT_URL, $url);
    } else {
        if ($params) {
            if (is_array($params)) {
                $params = http_build_query($params);
            }
            curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
        } else {
            curl_setopt($ch, CURLOPT_URL, $url);
        }
    }
    $response = curl_exec($ch);
    if ($response === FALSE) {
        return false;
    }
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
    curl_close($ch);
    return $response;
}

try this


print a log on the other side to see if there is a problem with url.

Menu