How to send data in http headers in php for calling another server Api-ThrowExceptions

Exception or error:

I have to call third party API which I need to send data in headers I am trying in cURL.

Is there any method to send data without curl on third party server which receiving on headers parameters.

This is what am trying but not succeed:


$headers = array
    'MobileNo', $MobileNo,
    'RequestNo', $RequestNo,
    'SMSText', $SMSText,
    'Content-Type: application/text'

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, '' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;

I want to send data as well as receive the response from the third server request.

How to solve:

You can try below code. Hope, it will help you.

$headers = array
    'Content-Type: application/json'

Leave a Reply

Your email address will not be published. Required fields are marked *