H
H
huurak2018-04-11 15:11:18
PHP
huurak, 2018-04-11 15:11:18

How to correctly write a type request in a php curl file?

How can I write such a request in a php file? Thanks in advance
curl -X POST ' https://a2p-api.megalabs.ru/sms/v1/sms ' --header "Content-Type:application/json" -d '{"from":"name"," to":79995551213,"message":"test"}' --user login:password

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sundrey, 2018-04-11
@sundrey


This is how $curl = curl_init(); should work .
$url = " https://a2p-api.megalabs.ru/sms/v1/sms ";
$login = "";
$password = "";
$post_string = json_encode(array("from"=>"name", "to"=>"79995551213", "message"=>"test"));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curl, CURLOPT_USERPWD, $login. ":" . $password);
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl,
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);// do not verify SSL certificate
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);// do not verify Host SSL certificate
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
$result = curl_exec($curl); // execute the request and write to a variable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question