我试图使用下面的代码将HTTP请求发送到URL,但始终存在错误
(file_get_contents(http://localhost:81/Help/Api/POST-SMS):未能打开流: HTTP请求失败!HTTP/1.1 500内部服务器错误)
有什么想法吗?提前感谢
<?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);
?>
发布于 2017-07-07 08:34:55
从服务器响应"HTTP请求失败!HTTP/1.1 500内部服务器错误“--这意味着http://localhost:81/Help/Api/POST-SMS失败--而不是上面发布的实际脚本。
我还建议在PHP中使用curl方法:http://php.net/manual/en/curl.examples-basic.php http://php.net/manual/en/book.curl.php
另一个可能帮助您的例子是:PHP + curl, HTTP POST sample code?
https://stackoverflow.com/questions/44965514
复制相似问题