0

I am trying to send an HTTP request to an URL using the below code,but keep getting error

(file_get_contents(http://localhost:81/Help/Api/POST-SMS): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error)

, any idea? Thank in advance

<?php

$url = 'http://localhost:81/Help/Api/POST-SMS';
 $data = array('message' => 'hi', 'mobile' => '12345678');
$options = array(
'http' => array(
    'header'  => "Content-type: application/json",
    '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);
?>
Muhammad Muazzam
  • 2,714
  • 6
  • 25
  • 53
Codezzz
  • 235
  • 1
  • 2
  • 12

1 Answers1

0

From the server response "HTTP request failed! HTTP/1.1 500 Internal Server Error" - that means the http://localhost:81/Help/Api/POST-SMS failed - not your actual script that you posted above.

I also recommend using the curl approach in PHP: http://php.net/manual/en/curl.examples-basic.php http://php.net/manual/en/book.curl.php

Another exemple that might help you is this: PHP + curl, HTTP POST sample code?