简体   繁体   English

将cURL命令行转换为PHP

[英]Converting cURL command line to PHP

This is the command line: 这是命令行:

curl --silent --header "Authorization: MyLogin auth=xxxxxxxxxxxxxxxxxxx" "https://www.myweb.com/"

I this is what I have (tried all kinds of variations with the header) 我这就是我所拥有的(用标题尝试了各种变化)

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "https://www.myweb.com");

    curl_setopt($ch,CURLOPT_HTTPHEADER,array('Authorization: MyLogin','auth: xxxxxxxxxxxxxxxxxxx'));

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $output = curl_exec($ch);

    curl_close($ch);

    echo $output;

I think I am messing up the header part, any help will be much appreciated. 我想我正在弄乱标题部分,任何帮助将不胜感激。 Thanks. 谢谢。

Added* This is what I am actually working with 添加*这就是我实际使用的内容

http://code.google.com/apis/gdata/articles/using_cURL.html#authenticating http://code.google.com/apis/gdata/articles/using_cURL.html#authenticating

I just rewrote it and now it works, this is what i have: 我只是重写了它,现在它有效,这就是我所拥有的:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: GoogleLogin auth=$authCode"));
    //curl_setopt($ch, CURLINFO_HEADER_OUT, true); // for debugging the request
    //var_dump(curl_getinfo($ch,CURLINFO_HEADER_OUT)); //for debugging the request
    $response = curl_exec($ch);
    curl_close($ch);

    echo $response;

I think the Authorization header should be sent all as one string, not as 2 header values. 我认为Authorization标头应该作为一个字符串发送,而不是作为2个标头值。

Try this line instead: 请尝试这一行:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: MyLogin auth: xxxxxxxxxxxxxxxxxxx'));

maybe you could check the CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST false to prevent any SSL certificate like issues.... also whats the error code that you get like a 403 access forbidden... any information on the Error or a Verbose based log would be much useful... hope my suggestion helps someway... 也许你可以检查CURLOPT_SSL_VERIFYPEERCURLOPT_SSL_VERIFYHOST假以防止任何SSL证书,如问题....还有你得到的错误代码,如403禁止访问...任何有关错误或基于详细的日志的信息将是非常有用的...希望我的建议有所帮助......

Cheers!! 干杯!!

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

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