Httprequest php error

Asked

Viewed 1,046 times

0

I cannot use the script because of the Httprequest class I already downloaded several classes and always error: (https://dev.infobip.com/docs/fully-featured-textual-message)

$request = new HttpRequest();
$request->setUrl('https://api.infobip.com/sms/1/text/advanced');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'accept' => 'application/json',
  'authorization' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
  'content-type' => 'application/json'
));

$request->setBody('{
   "bulkId":"BULK-ID-123-xyz",
   "messages":[
      {
         "from":"InfoSMS",
         "destinations":[
            {
               "to":"41793026727",
               "messageId":"MESSAGE-ID-123-xyz"
            },
            {
               "to":"41793026731"
            }
         ],
         "text":"Artık Ulusal Dil Tanımlayıcısı ile Türkçe karakterli smslerinizi rahatlıkla iletebilirsiniz.",
         "flash":false,
         "language":{
            "languageCode":"TR"
         },
         "transliteration":"TURKISH",
         "notifyUrl":"http://www.example.com/sms/advanced",
         "notifyContentType":"application/json",
         "callbackData":"DLR callback data",
         "validityPeriod": 720
      },
      {
         "from":"41793026700",
         "destinations":[
            {
               "to":"41793026785"
            }
         ],
         "text":"A long time ago, in a galaxy far, far away... It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire.",
         "sendAt":"2015-07-07T17:00:00.000+01:00"
      }
   ]
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

So it worked All right thanks for Help MIGUEL the right code got:

    <?php
$data_string = '{
                           "messages":[
                              {
                                 "from":"InfoSMS",
                                 "destinations":[
                                    {
                                       "to":"5517998652984"
                                    }
                                 ],
                                 "text":"O SMS chegou!",
                                 "flash":true
                              }
                            ]
                        }';


$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://api.infobip.com/sms/1/text/advanced",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => $data_string,
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "authorization: Basic QnbcXX6735BYH==",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>

  • What’s the mistake that comes?

  • Class Https No Found

  • What is the API URL, the one that sends the text, that’s what you want right? Send a text?

  • this send sms to url is:

  • http://api.infobip.com/tts/3/single

  • Have you tried their example? at the end of this page https://dev.infobip.com/docs/send-single-sms, at the bottom where it says "https://dev.infobip.com/docs/send-single-sms", in the request section there is a tab that has an example of php

  • tried but also uses error ai httpsrequest class

Show 2 more comments

1 answer

1


Try the following by doing Curl:

$headers = array(
  'accept' => 'application/json',
  'content-type' => 'application/json',
  'authorization' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
);
$data_string = '{
   "bulkId":"BULK-ID-123-xyz",
   "messages":[
      {
         "from":"InfoSMS",
         "destinations":[
            {
               "to":"41793026727",
               "messageId":"MESSAGE-ID-123-xyz"
            },
            {
               "to":"41793026731"
            }
         ],
         "text":"Artık Ulusal Dil Tanımlayıcısı ile Türkçe karakterli smslerinizi rahatlıkla iletebilirsiniz.",
         "flash":false,
         "language":{
            "languageCode":"TR"
         },
         "transliteration":"TURKISH",
         "notifyUrl":"http://www.example.com/sms/advanced",
         "notifyContentType":"application/json",
         "callbackData":"DLR callback data",
         "validityPeriod": 720
      },
      {
         "from":"41793026700",
         "destinations":[
            {
               "to":"41793026785"
            }
         ],
         "text":"A long time ago, in a galaxy far, far away... It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire.",
         "sendAt":"2015-07-07T17:00:00.000+01:00"
      }
   ]
}';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT ,0); 
curl_setopt($curl, CURLOPT_TIMEOUT, 40);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_URL, 'https://api.infobip.com/sms/1/text/single');
curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1');
$return = curl_exec($curl);
curl_close($curl);
echo $return;
  • gave some error in my PHP ai to tidying and testing here

  • shows nothing I executed the code only it does nothing

  • yes I did think Curl is not giving the site time to reply

  • pq in javascript takes about 10 seconds to show in LOG that the message was sent

  • thank you, I’ll try

  • I put the set_time_limit(0) and nothing the script opens normal except that nothing appears the site is empty or error anything. Is it the CURLOPT_USERAGENT that is as mozila mine is Chrome? has something to do

  • no, I’m also surprised it doesn’t exactly do anything

  • I found in infobip this link:https://dev.infobip.com/docs/single-voice-message and has in CURL only for other type of SMS I tried to adapt but it was error

  • I’ll try to send it to my server if it gives a different answer

  • now I got got the same error that in the image you sent, but it was not to give error

  • I found in infobip this link:dev.infobip.com/Docs/single-voice-message and has in CURL only that for another type of SMS I tried to adapt but gave error

  • ae you were more than enough helped me enough I managed to join the infobip code with yours and worked to 1 week already trying and got VLW even the code was like this:

  • sorry, first time I walk on this site and found nothing to give accepted

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.