2017-02-16 50 views
1

我在AWS中的EC2实例中部署了Laravel v4 PHP应用程序。一个我的脚本使用CURL调用同一个域中的POST路由,但没有得到任何结果。但是,如果我检查邮差的POST路线上,我得到的(JSON)结果为什么我的PHP CURL POST返回空结果

,使PHP卷曲POST调用的代码如下:

$data_json = json_encode(array('company_id' => 100)); 
$url = 'http://somedomain.com/rest/getcompanyprofile'; 
curl_setopt($ch,CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_json))); 

$result = curl_exec($ch); 
curl_close ($ch); 
$obj = json_decode($result); 

die(var_dump($obj)); 

$ result变量应该包含JSON回报值$ obj,$ result的字符串解码。 die语句显示NULL。

http://somedomain.com/rest/getcompanyprofile的呼叫路由代码如下:

public function fetchCompanyprofile(){ 
    $company_id = Input::get('company_id'); 

    $company_record = DB::table('company')->select('company_name', 'company_email', 'company_phone', 'company_CEO')->where('company_id', $company_id)->first(); 
    $company_name = $company_record->company_name; 
    $company_email = $company_record->company_email; 
    $company_CEO = $company_record->company_CEO; 

    $response = array('company_name' => $company_name, 'company_email' => $company_email, 'company_CEO' => $company_CEO); 

    return Response::json($response); 
} 

我使用邮差应用测试http://somedomain.com/rest/getcompanyprofile。 Sofar,我得到了JSON结果。

我在行后插入了下面的代码$ result = curl_exec($ ch);现在

if(curl_error($ch)){ 
    die('CURL error: ' . curl_error($ch)); 
} 

,我越来越无法连接到http://somedomain.com:80;连接超时

我需要做些什么修复?

回答

0

您是否创建了安全组,以便在实例之间允许TCP 80上的传入流量