2

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:

$MobileNo=$_POST['MobileNo'];
$SMSText=$_POST['SMSText'];

$remarks=$_POST['remarks'];
$RequestNo=$_POST['RequestNo'];
$headers = array
(
    'MobileNo', $MobileNo,
    'RequestNo', $RequestNo,
    'SMSText', $SMSText,
    'Content-Type: application/text'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'http://example.com/api/SendEnglishSMS' );
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.

Madan Sapkota
  • 25,047
  • 11
  • 113
  • 117
sumit kundan
  • 163
  • 2
  • 11
  • 1
    Possible duplicate of [PHP cURL custom headers](https://stackoverflow.com/questions/8115683/php-curl-custom-headers) – Ali Jouadi Jul 02 '19 at 07:46
  • 1
    Shouldn't the headers be: `'MobileNo: ' . $MobileNo,`? As it is now, you're creating one header with `MobileNo` and then another header with the value of `$MobileNo`. – M. Eriksson Jul 02 '19 at 07:47
  • I need to create three header one for MobileNo, RequestNo and SMSText – sumit kundan Jul 02 '19 at 08:19

1 Answers1

1

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

$headers = array
(
    'MobileNo:'.$MobileNo,
    'RequestNo:'.$RequestNo,
    'SMSText:'.$SMSText,
    'Content-Type: application/json'
);
showdev
  • 28,454
  • 37
  • 55
  • 73
J. Sel
  • 23
  • 1
  • 10