简体   繁体   English

Apache服务器返回空-curl-PHP for PHP

[英]Apache server returning empty - curl - php for php

Good afternoon. 下午好。 I am facing a very specific problem. 我面临一个非常具体的问题。 It turns out that I have an application running on a server in the clouds (hostigator - php) that makes calls via curl on a server hosted on my client. 事实证明,我有一个在云中的服务器(hostigator-php)上运行的应用程序,该应用程序通过curl在客户端上托管的服务器上进行调用。 (apache - php). (Apache-PHP)。 Access is made via IP or ddns. 通过IP或ddns进行访问。 When I make the call (get) right in the browser, it returns json normally, but when I call the server in the clouds (hostigator) it returns an empty string. 当我在浏览器中进行调用(获取)时,它通常会返回json,但是当我在云端(hostigator)中调用服务器时,它将返回一个空字符串。

No php that is on the server has the following header. 服务器上没有任何php具有以下标头。

header ("Content-Type: application / json"); 标头(“ Content-Type:应用程序/ json”);

Calling method 调用方式

$app->get('/getCidades/:id',    function ($id) use ($app, $db) {
$data = json_decode($app->request()->getBody());   
$ch = curl_init();
$url = $_SESSION['ip'] . $GLOBALS['servico'] . "getCidades/" . $id;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,10); //timeout in seconds
curl_setopt($ch,CURLOPT_TIMEOUT, 20); // same for here. Timeout in seconds.
$response = curl_exec($ch);
curl_close ($ch); //close curl handle    
echo $response;
}
);

Server in client header("Content-Type: application/json"); 客户端头中的服务器(“ Content-Type:应用程序/ json”); header("Content-type: text/html; charset=utf-8"); header(“ Content-type:text / html; charset = utf-8”);

$app->get(
'/getCidades/:id', 
function ($id) use ($app) {        
$conexao = ibase_connect( $GLOBALS['hostname'], $GLOBALS['usuario'],                 
$GLOBALS['senha'] ) or die( 'Erro ao conectar: ' . ibase_errmsg() );
$Ds_Query = "select DISTINCT PESSOAS.cidade2, PESSOAS.uf2 from PESSOAS where 
cidade2 <> '' and uf2 is not null order by cidade2";
$Ds_Retorno = ibase_query( $Ds_Query );
$results = array();
while ( $Ds_Linha_Banco = ibase_fetch_row( $Ds_Retorno ) )
{
$row = new Cidade();
$row->cidade = clean($Ds_Linha_Banco[0]);
$row->uf = $Ds_Linha_Banco[1]; 
$results[] = $row;
}
ibase_close($conexao);
echo json_encode(array("list"=>$results));    
}  
);

Maybe you are missing the parameter CURLOPT_POST . 也许您缺少参数CURLOPT_POST When you open a url using a web browser, the request is processed using a GET method, but in this case the HTTP VERB is not defined. 使用Web浏览器打开URL时,将使用GET方法处理请求,但是在这种情况下,未定义HTTP VERB。 Try add this and post back to us :) 尝试添加此内容并发回给我们:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM