相关疑难解决方法(0)

如何解决cURL错误(7):无法连接到主机?

我使用cUrl(php)将项目代码以xml格式发送到Web服务.我在localhost中得到了正确的响应,但是什么时候服务器显示它

cURL错误(7):无法连接到主机

这是我的代码:

function xml_post($post_xml, $url)
{
    $user_agent = $_SERVER['HTTP_USER_AGENT'];

    $ch = curl_init();    // initialize curl handle
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);          
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 50); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); 
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
//  curl_setopt($ch, CURLOPT_PORT, $port);          

    $data = curl_exec($ch);
    $curl_errno = curl_errno($ch);
    $curl_error = curl_error($ch);
    if ($curl_errno > 0) {
            echo "cURL Error ($curl_errno): $curl_error\n";
    } else {
            echo "Data received\n";
    }
    curl_close($ch);

    echo $data;
}
Run Code Online (Sandbox Code Playgroud)

我将商品代码发送到计数器并从中获取详细信息.我尝试使用php 4+和php5 +两个版本,没有任何解决方案.

php xml curl

56
推荐指数
5
解决办法
39万
查看次数

从 Guzzle 中捕获 cURL 错误

我有以下代码可以发出 Guzzle 4.1 请求:

$client = new \GuzzleHttp\Client(['defaults/headers/User-Agent' => $userAgentString]);

$retry = 0;

do {
    try {
        return $client->post($url, $options);
    } catch (\Exception $e) {
        echo $e->getMessage();
        $retry++;
        continue;
    }
} while ($retry < 3);
Run Code Online (Sandbox Code Playgroud)

它愉快地运行了很长一段时间,但在随机的时间间隔内,它有时会遇到 cURL CA 文件的问题,由于未捕获的异常而导致致命错误。我不确定我能不能做到这一点,因为我已经把它放在一个try catch街区里了。

这是取消我的 Laravel 控制台命令的错误:

cURL error 77: error setting certificate verify locations:
  CAfile: /home/vagrant/Projects/test.dev/laravel/vendor/guzzlehttp/guzzle/src/cacert.pem
  CApath: /etc/ssl/certs (0)
PHP Fatal error:  Uncaught exception 'ErrorException' with message 'include(/home/vagrant/Projects/test.dev/laravel/vendor/filp/whoops/src/Whoops/Exception/Inspector.php): failed to open stream: Too many open files' in /home/vagrant/Projects/test.dev/laravel/vendor/composer/ClassLoader.php:382
Run Code Online (Sandbox Code Playgroud)

我想要做的不仅是找出 Guzzle 收到此 …

php curl guzzle

5
推荐指数
0
解决办法
1692
查看次数

标签 统计

curl ×2

php ×2

guzzle ×1

xml ×1