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.

3
  • 1
    Possible duplicate of PHP cURL custom headers Commented Jul 2, 2019 at 7: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. Commented Jul 2, 2019 at 7:47
  • I need to create three header one for MobileNo, RequestNo and SMSText Commented Jul 2, 2019 at 8:19

1 Answer 1

1

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

$headers = array
(
    'MobileNo:'.$MobileNo,
    'RequestNo:'.$RequestNo,
    'SMSText:'.$SMSText,
    'Content-Type: application/json'
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.