最新更新:脚本通过SSH shell成功运行为"php script.php",作为管理员用户.当由nginx用户运行时,curl命令无法执行https请求.所以我想这是nginx用户无法正确使用curl的问题.我检查了十分之一的配置文件,但无法找到可以更改的位置.
我正在尝试发布以下JSON
{ "where": { "userId": "97" }, "data": { "alert": "Joe Masilotti answered a question you follow", "badge": "Increment","eventId":"3","questionId":"8954","answerId":"977" } }
使用以下代码
$c = curl_init(); curl_setopt($c, CURLOPT_TIMEOUT, 30); curl_setopt($c, CURLOPT_USERAGENT, 'parse.com-php-library/2.0'); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c, CURLINFO_HEADER_OUT, true); curl_setopt($c, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'X-Parse-Application-Id: '.$this->_appid, 'X-Parse-REST-API-Key: '.$this->_restkey )); curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'POST'); $postData = str_replace(PHP_EOL,'',$args['data']); curl_setopt($c, CURLOPT_POSTFIELDS, $postData ); $url = $this->_parseurl . $args['requestUrl']; curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($c);
它适用于我的本地Apache.我在运行在AWS EC2上的nginx服务器上运行此命令并从cURL获取此服务器
Array ( [url] => https://api.parse.com/1/push [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.012399 [namelookup_time] => 0.01232 [connect_time] => 0.013486 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array ( ) [redirect_url] => ) cURL error number:77 cURL error:
使用以下命令从AWS EC2服务器的命令行发送相同的JSON
curl -X POST \ -H "X-Parse-Application-Id: <...>" \ -H "X-Parse-REST-API-Key:<..>" \ -H "Content-Type: application/json" \ -d '{ "where": { "userId": "97" }, "data": { "alert": "Joe answered a question", "badge": "Increment","eventId":"3","questionId":"8954","answerId":"977" } }' \ https://api.parse.com/1/push
cURL扩展在服务器上正确设置,并且可以在其他脚本中使用.谢谢!
更新:脚本"script.php"在服务器上从命令行以"php script.php"运行时成功运行,而在" http://www.mysite.com/script.php " 浏览器上请求时失败
更新:这是我的卷曲-V
curl 7.36.0 (x86_64-redhat-linux-gnu) libcurl/7.36.0 NSS/3.16 Basic ECC zlib/1.2.7 libidn/1.18 libssh2/1.4.2 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz
我试图检查我的本地和服务器PHP配置之间的卷曲差异,我看到本地卷曲SSL版本是OpenSSL/1.0.1f,而在服务器上是NSS/3.14.3.0
我在亚马逊AMI linux上有同样的错误.
我通过在/etc/php.d/curl.ini上设置curl.cainfo来解决
检查我的curl.ini https://gist.github.com/reinaldomendes/97fb2ce8a606ec813c4b