php - 关于 CURL 中 URL 设置的 PHP 查询
问题描述
我是 PHP 新手,几个小时前才开始探索它。
我在 Openshift 工作并部署了一个 CustomerApp Pod,它有一个 Service namecustomer
和 port 8080
。
index.php
我在具有以下内容的同一项目/命名空间中部署了另一个简单的 PHP 应用程序。当我尝试调用我的 PHP 应用程序的 Route 时,它给出了 503 错误。
我想http://customer:8080
被视为字符串而不是 URL。我应该添加什么来告诉 PHP 它应该被视为一个 URL?
<?php
$url="http://customer:8080";
$client=curl_init($url);
curl_setopt($client,CURLOPT_RETURNTRANSFER,1);
$response=curl_exec($client);
echo $response;
?>
解决方案
curl_init()
通话不需要 arg -
$url = "https://api.example.com:8000/get/some/info";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_result = curl_exec($ch);
curl_close($ch);
推荐阅读
- pine-script - 在“松脚本”的移动平均线上绘制水平线
- python - 笛卡尔坐标数组到python中的极坐标
- types - 如何在 postgresql 类型中插入类型
- java - 在异常时将可完成的未来加入当前线程
- azure - 应用详解-Azure App Service for Linux 中的 Http 日志
- javascript - 如何在 Chrome 扩展中使用 ajax 向 IMAP 发送请求?
- c# - 控制器中的电子邮件链接
- python - 如何让 try/except 正常工作
- python - groupby中按日期时间过滤的有效方法
- python - 我在 while 循环中遇到了 tkinter mainloop 的问题