简体   繁体   English

curl php相同的代码在ubuntu上工作正常但在wamp windows 8上没有

[英]curl php same code works fine on ubuntu but not on wamp windows 8

Am not familiar with Php and I have a problem with running this code on windows curl_php is enabled and there no errors when I execute the code but i have a blank screen while on ubuntu I got a result , I also disabled firewall but still nothing 我不熟悉Php,我在windows上运行此代码有问题curl_php已启用且执行代码时没有错误但是我在ubuntu上有空白屏幕我得到了结果,我也禁用了防火墙但仍然没有

 $username = "myusername";
 $password = "mypasword";  
 $host = "https://myurl";

 $process = curl_init($host);
 curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
 curl_setopt($process, CURLINFO_HEADER_OUT, false);
 curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
 curl_setopt($process, CURLOPT_TIMEOUT, 30);
 curl_setopt($process, CURLOPT_CUSTOMREQUEST, 'GET');

 echo curl_exec($process);

The solution is to disable ssl verifying (yep, it uses https =) ) 解决方案是禁用ssl验证(是的,它使用https =))

Code: 码:

<?php 

$username = "myusername"; 
$password = "mypassword"; 
$url = "https://myurl"; 

$process = curl_init($url); 
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
curl_setopt($process, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($process, CURLINFO_HEADER_OUT, true); 
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password); 
curl_setopt($process, CURLOPT_TIMEOUT, 30); 
curl_setopt($process, CURLOPT_CUSTOMREQUEST, 'GET'); 
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($process, CURLOPT_SSL_VERIFYHOST, false);

echo curl_exec($process);

curl_close($process);

Try to debug. 尝试调试。 Add the following code to beginning of php file right after <?php (on new line): <?php (在新行)之后立即将以下代码添加到php文件的开头:

error_reporting(E_ALL|E_NOTICE);
ini_set('display_errors', 'On');

And refresh your page. 并刷新您的页面。 You wil probably see an error if it exists; 如果它存在,你可能会看到错误;

If not, add the following after last curl_setopt call: 如果没有,请在最后一次curl_setopt调用后添加以下内容:

echo 'errno: ', curl_errno($process), ', error: ', curl_error($process), "\n";

You will probably see an error. 你可能会看到一个错误。

After that we can try to help you to solve the problem; 之后我们可以尝试帮助您解决问题;

Maybe there's a redirect to another page, and your windows php installation uses open_basedir restriction. 也许有一个重定向到另一个页面,你的Windows php安装使用open_basedir限制。 Or maybe something else =) 或者别的东西=)

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

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