php - laravel guzzle 无法正常工作页面卡在重新加载
问题描述
public function getGuzzleRequest()
{
$client = new \GuzzleHttp\Client();
$request = $client->get('http://localhost:8000/api/v1/poster');
$response = $request->getBody();
print_r($response);
}
laravel guzzle 无法正常工作页面卡在重新加载
解决方案
PHP 开发服务器 (artisan: serve) 中的构建是单线程的,因此会挂起,例如http://localhost:8000将不起作用。尝试使用真实服务器(Apache /nginx)。像' http://ip.jsontest.com '
public function getGuzzleRequest(){
$client = new Client();
$request = $client->get('http://youripadress:8000/api/v1/poster');
$response = $request->getBody()->getContents();
print_r($response);
}
您也可以使用 php curl 功能提供替代方案。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$targeturl);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
curl_exec ($ch);
curl_close ($ch);
但请确保您使用的是真实服务器,如果可能的话,用您的 IP 地址补充 localhost
如何在命令行或终端上获取您的 ip 地址
运行ifconfig
命令并检查前面的数字inet
。
你可以通过 php 了解更多关于guzzle 文档和curl 请求的内容
推荐阅读
- sql - 在 SQL Server 存储过程中迭代查询结果
- python - 如何为在 Windows 10 上运行 Python 2.7.5 的 IDLE 安装 PIP?
- reactjs - 在material-ui中将主要内容定位在appbars和drawers周围的正确方法是什么?
- reactjs - 当我单击删除按钮 reactjs 时没有任何反应
- javascript - 同一个选择器上的多个 Html 方法
- c - 缓存提供的空间局部性是指虚拟内存、物理内存还是两者兼而有之?
- python - 互信息的Tensorflow成对自定义损失
- r - R中与p值的多变量相关性
- angular - Angular惰性路由忽略父路径
- python - 如何简化 SSL DNS 验证?