PHP CURL不返回任何内容 [英] PHP CURL returns nothing

查看:481
本文介绍了PHP CURL不返回任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function ParseUrl($URL)
{
    $crl = curl_init();
    curl_setopt ($crl, CURLOPT_URL, $URL);
    curl_setopt ($crl, CURLOPT_PORT, 8086);
    curl_setopt ($crl, CURLOPT_USERPWD, "admin:pass");
    curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, 5);
    $ret = curl_exec($crl);
    curl_close($crl);
    return $ret;
}

echo ParseUrl('http://xxx.me/serverinfo');

上面的代码不会返回任何内容。我试图用curl获取的页面使用http验证的东西。

The code above simply returns nothing. The page I am trying to get with curl uses http authentication thing.

我缺少一些简单的东西或什么?

Am I missing something simple or what?

推荐答案

开始这样做,看看你得到什么,然后很明显的问题是什么:

Start out by doing this and see what you get, and after that it would be pretty obvious what the problem is:

检查curl_exec后的请求是否有错误:

Check if there was an error with the request after curl_exec:

if(curl_errno($ch)){
    echo 'Curl error: ' . curl_error($ch);
}

这将提供足够的信息来了解请求。如果没有错误,您可以检查curl_exec后发送的请求,以便您可以仔细检查发送的一切是否到位:

That will provide you with enough info to know if there was a error with the request. If there was no error, you can check the request sent after curl_exec so you can double check that everything sent is in place:

print_r(curl_getinfo($ch));

编辑:注释后这是你正在寻找什么缺少:

您需要设置选项 CURLOPT_HTTPAUTH

报价php.net关于主题


使用HTTP认证方法
。选项是:CURLAUTH_BASIC,
CURLAUTH_DIGEST,
CURLAUTH_GSSNEGOTIATE,CURLAUTH_NTLM,
CURLAUTH_ANY和CURLAUTH_ANYSAFE。

The HTTP authentication method(s) to use. The options are: CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NTLM, CURLAUTH_ANY, and CURLAUTH_ANYSAFE.

(或)运算符可以
用于组合多个方法。
如果这样做,cURL将轮询
服务器以查看它支持
的方法并选择最好的方法。

The bitwise | (or) operator can be used to combine more than one method. If this is done, cURL will poll the server to see what methods it supports and pick the best one.

CURLAUTH_ANY是
CURLAUTH_BASIC |的别名CURLAUTH_DIGEST |
CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM。

CURLAUTH_ANY is an alias for CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM.

CURLAUTH_ANYSAFE是
的别名CURLAUTH_DIGEST |
CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM。

CURLAUTH_ANYSAFE is an alias for CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM.

这篇关于PHP CURL不返回任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆