简体   繁体   English

为什么我的PHP CURL POST返回空结果

[英]Why does my PHP CURL POST return a null result

I have a Laravel v4 PHP app deployed in an EC2 instance in AWS. 我在AWS的EC2实例中部署了Laravel v4 PHP应用程序。 One my my script calls a POST route in the same domain using CURL but is not getting any result. 我的一个脚本使用CURL在同一域中调用POST路由,但未得到任何结果。 But if I check on the POST route in Postman, I get the (JSON) result 但是如果我检查Postman中的POST路由,就会得到(JSON)结果

The code that makes the PHP CURL POST call is below: 进行PHP CURL 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));

The $result variable should contain the JSON return value while $obj, the string decoded of $result. $ result变量应包含JSON返回值,而$ obj是解码后的$ result字符串。 The die statement displays NULL. die语句显示NULL。

The route for http://somedomain.com/rest/getcompanyprofile calls the code below: 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);
}

I'm using Postman app to test http://somedomain.com/rest/getcompanyprofile . 我正在使用Postman应用测试http://somedomain.com/rest/getcompanyprofile Sofar, Im getting the JSON result. Sofar,我正在获取JSON结果。

I've inserted the code below after the line $result = curl_exec($ch); 我在$ result = curl_exec($ ch);行之后插入了下面的代码

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

Now, I'm getting Failed to connect to http://somedomain.com:80 ; 现在,我无法连接到http://somedomain.com:80 ; Connection time out 连接超时

What fixes do I need to make? 我需要进行哪些修复?

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

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

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