首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用PHP向URL发送HTTP请求

使用PHP向URL发送HTTP请求
EN

Stack Overflow用户
提问于 2017-07-07 07:57:21
回答 1查看 1.1K关注 0票数 0

我试图使用下面的代码将HTTP请求发送到URL,但始终存在错误

(file_get_contents(http://localhost:81/Help/Api/POST-SMS):未能打开流: HTTP请求失败!HTTP/1.1 500内部服务器错误)

有什么想法吗?提前感谢

代码语言:javascript
运行
复制
<?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);
?>
EN

回答 1

Stack Overflow用户

发布于 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?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44965514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档