capcom6/android-sms-gateway

send curl by php

Closed this issue · 0 comments

I want to use Curl with php and this my code
`<?php
$data = array("message" => "test","phoneNumbers" => ["+9647846037077"]);
// data u want to post
$data_string = json_encode($data);
$api_key = "sms";
$password = "hTPJJ0Gl";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.129.35:8080");

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( array($data_string) ));
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_USERPWD, $api_key.':'.$password);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json') );

if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
$errors = curl_error($ch); $result = curl_exec($ch);
$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch); echo $returnCode; var_dump($errors);
print_r(json_decode($result, true));

?>`

but I have 405 error not allowed