3

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

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;
tshepang
  • 12,111
  • 21
  • 91
  • 136
iamdamnsam
  • 41
  • 3

2 Answers2

1

I think the Authorization header should be sent all as one string, not as 2 header values.

Try this line instead:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: MyLogin auth: xxxxxxxxxxxxxxxxxxx'));
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • Yeah I have tried it that way, as well as with = instead of :, thanks though. I am thinking I may be calling the wrong header type of call, though I don't know what else to use. – iamdamnsam Nov 23 '11 at 18:18
0

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...

Cheers!!

optimusprime619
  • 754
  • 2
  • 17
  • 38
  • I gave those a try, still same. This is the error, it just isn't validating though it works perfect at command line { "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Invalid Credentials" } } – iamdamnsam Nov 23 '11 at 18:48
  • @user1062332 guess you could check [this](http://stackoverflow.com/questions/1304974/set-authorization-header-using-php-and-curl) might prove useful in your case – optimusprime619 Nov 23 '11 at 18:59
  • Thanks but that didn't help me. I have tried every combo of what is used in the command line version and it still doesn't work. – iamdamnsam Nov 23 '11 at 19:32