HostGator won't connect via cURL to an Amazon API

心不动则不痛 提交于 2019-12-24 10:49:45

问题


The following code executes no problem on 2 other servers I have access to and use to run on Hostgator. Hostgator tech support refuse to help as they feel it's an issue with the code. I get no response from the API unless I change the HTTPS to HTTP in which case I get a 307 redirect message from cloudfront.net. Any ideas on what a solution might be?

$data = array(
  "status" => "Quote",
  "job_address" => "1 Infinite Loop, Cupertino, California 95014, United States",
  "job_description" => "Client has requested quote for service delivery"
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.servicem8.com/api_1.0/Job.json');
curl_setopt($ch, CURLOPT_USERPWD, "xxx@xxxxx.com:password");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_VERBOSE , true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Accept: application/json'));

$response = curl_exec($ch);
var_dump($response);

回答1:


The answer to my problem was fairly specific. In short, I was running PHP5.4 on my Hostgator environment which was not allowing appropriate SSL handshakes to happen... The solution was to upgrade to PHP 5.6



来源:https://stackoverflow.com/questions/49662671/hostgator-wont-connect-via-curl-to-an-amazon-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!