0

I'm trying a new service to do a specific task, they have a pretty basic API which lets the users build simple apps. An example of the HTTP request is:

https://domainname.com/dashboard/api
?to={PHONE NUMBER}&from={SENDER ID}&message={TEXT}
&email={YOUR EMAIL}&api_secret={API SECRET}
&unicode={TRUE/FALSE}&id={IDENTIFIER}

I have tried everything, using postman,php and googling for the past 3 hours and i can't get it to work. (even tried to send it through the browser lol)

Whats a proper way to send a http request?

Thank you.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
hopw Jan
  • 39
  • 5

1 Answers1

0

You can send an HTTP request without CURL using PHP5. This answer is based off of How do I send a POST request with PHP?. You'll have to enter your variables into the $data array.

$url = 'https://domainname.com/dashboard/api';
$data = array('to' => PHONE_NUMBER, 'from' => SENDER_ID, 'message' => TEXT, 'email' => EMAIL, 'api_secret' => SECRET, 'unicode' => BOOLEAN, 'id' => IDENTIFIER);

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);

You can test if your requests are working from your script by using http://www.postb.in or some other similar service. This allows you to see your requests to debug them (rather than relying on feedback/errors from the service you are using). Then you'll know if your requests are formatted correctly and working. Sometimes a service is down... and you spend hours troubleshooting something that's not on your end.

Jeff Vdovjak
  • 1,833
  • 16
  • 21
  • Thank you so much. I have a really dumb question mostly because i'm new to all this. Do i just create a php file and then run it on my apache server? (i went this far with google but i had no idea how to properly run it..) – hopw Jan Mar 02 '20 at 20:24
  • PHP is processed before the webpage is delivered to the user. So you can include this code on the same page you would visit on your website. All the variables would have to be set BEFORE the visitor visits the page. So to try it out and see if it works, I would put in dummy variables that work (e.g. your phone number, etc so you can test it). And then visit the page (e.g. www.yourdomain.com/thispage.php). If it works, you can move to the next stage of making it interactive. But for that, you will need Javascript too. – Jeff Vdovjak Mar 02 '20 at 20:37
  • Thank you so much ♥ – hopw Jan Mar 02 '20 at 20:38