简体   繁体   中英

why PHP + curl, HTTP POST request returns null?

i am confused why $response does not return anything ,i am new to curl please help,

$post = [
        'AreaCode' => '02',
        'PhoneNumber' => '33312733',
        'InquiryBy'   => 'telephone',
    ];

    $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, 'https://billing.te.eg/api/Account/Inquiry');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
       'Content-Type:application/json',
       'Access-Control-Allow-Origin: *',
     ));
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     $httpCode = curl_getinfo($ch , CURLINFO_HTTP_CODE); 
     $response = curl_exec($ch);
     if ($response === false) $response = curl_error($ch);
     echo stripslashes($response);
     curl_close($ch);

while in postman

在此处输入图片说明

请添加以下行以定义请求类型(GET / POST / ..),然后尝试:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

Download cacert.pem file keep in root directory and set curl option and try

http://curl.haxx.se/ca/cacert.pem

curl_setopt ($h, CURLOPT_CAINFO, base_path()."/cacert.pem");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM