首页 > 解决方案 > 关于 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;
?>

标签: phpopenshiftopenshift-origin

解决方案


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);

推荐阅读