cURL / Mailing Lists / curl-users / Single Mail

curl-users

trying to login youtube

From: Bhadraji D <bhadraji.d_at_allaboutif.com>
Date: Tue, 10 Nov 2009 17:54:35 +0530

Hi i am trying to login youtube account using curl api .while sending POST
request so i am getting following error

Disables POST, goes with GET

from command line also i am not able to login

$curl -v --cookie cjar -d "username=xxxxxx&password=xxxxxxxx" '
https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Den_US%26next%3D%252F&hl=en_US&ltmpl=sso
'
* About to connect() to www.google.com port 443 (#0)
* Trying 209.85.231.147... Timeout
* Trying 209.85.231.99... Timeout
* Trying 209.85.231.104... Timeout
* connect() timed out!
* Closing connection #0
curl: (28) connect() timed out!

About to connect() to proxy proxy.xxxxx.net port 3128 (#0)
* Trying 192.168.1.1... * connected
* Connected to proxy.xxxxx.net (192.168.1.1) port 3128 (#0)
> POST http://www.youtube.com/login HTTP/1.1
Host: www.youtube.com
Accept: */*
Proxy-Connection: Keep-Alive
Cookie: GEO=c8e8fc1877bd3659cf3cd93244d27fcccwsAAAAzSU56rDUlSvk2gA==;
PREF=f1=10000000; VISITOR_INFO1_LIVE=2wnXu_gnmOk;
use_hitbox=72c46ff6cbcdb7c5585c36411b6b334edAEAAAAw
Content-Length: 81
Content-Type: application/x-www-form-urlencoded

* HTTP 1.0, assume close after body
< HTTP/1.0 303 See Other
< Date: Tue, 10 Nov 2009 12:11:14 GMT
< Server: Apache
< X-Content-Type-Options: nosniff
< Expires: Tue, 27 Apr 1971 19:44:06 EST
< Content-Length: 0
< X-YouTube-MID:
WkFSZzctYUFHdmc5OWpzdnhWTjRRTFRkU1JWTGxObnR0QUR6MzFYdWZsSEdEUmJ1OG9EdXJ3
< Cache-Control: no-cache
< Location:
https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Dhi_IN%26next%3D%252F&hl=hi_IN&ltmpl=sso
< Content-Type: text/html; charset=utf-8
< X-XSS-Protection: 0
< X-Cache: MISS from server.xxxxx.net
< X-Cache-Lookup: MISS from server.xxxxx.net:3128
< Via: 1.0 server.xxxxx.net:3128 (squid/2.6.STABLE21)
* HTTP/1.0 proxy connection set to keep alive!
< Proxy-Connection: keep-alive
<
* Connection #0 to host proxy.xxxxx.net left intact
* Issue another request to this URL: '
https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Dhi_IN%26next%3D%252F&hl=hi_IN&ltmpl=sso
'
* Disables POST, goes with GET
* About to connect() to www.google.com port 443 (#1)
* Trying 209.85.231.99... * Timeout
* Trying 209.85.231.104... * Timeout
* Trying 209.85.231.147...

following is my code
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
static const char __FILE_COOKIE[] = {"cookie"};
static const char __FILE_LOGIN[] = {"loging"};

static const char __YOUTUBE_URL_LOGIN[] = {"http://www.youtube.com/login"};

 int youtube_status;

/* configure an easy cURL handle */
CURL *handle_config(CURL *handle, FILE *stream, const char *url,
  char *error_buf, int p_use, void *p_func, void *p_data, char *post)
{
  curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, error_buf);
  curl_easy_setopt(handle, CURLOPT_URL, url);
  curl_easy_setopt(handle, CURLOPT_WRITEDATA, stream);
  curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L);
  curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);
  curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  curl_easy_setopt(handle, CURLOPT_SSLVERSION, 3);
  curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L);
  curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 1L);
  //curl_easy_setopt(handle, CURLOPT_NOPROGRESS, !p_use);
  //curl_easy_setopt(handle, CURLOPT_PROGRESSDATA, p_data);
  //curl_easy_setopt(handle, CURLOPT_PROGRESSFUNCTION, p_func);

  curl_easy_setopt(handle, CURLOPT_COOKIEFILE,__FILE_COOKIE);
  curl_easy_setopt(handle, CURLOPT_COOKIEJAR, __FILE_COOKIE);

  if (post)
  {
     curl_easy_setopt(handle, CURLOPT_POST, 1);
     curl_easy_setopt(handle, CURLOPT_POSTFIELDS, post);
    curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, strlen(post));
  }

  return handle;
}

/* login to youtube */
int login_perform()
{
  FILE *stream = NULL;
  CURL *handle = NULL;
  char *post = NULL;
  char *url = NULL;

  if (!(stream = fopen(__FILE_LOGIN, "w+")))

    if(stream == NULL)
       printf("failed to open the file\n");

    //return youtube_status = 0;

  if ((handle = curl_easy_init()))
  {
    post
="current_form=loginForm&Username=xxxxx&Password=xxxx&action_login=Log+In";

      handle = handle_config(handle, stream, __YOUTUBE_URL_LOGIN,
        NULL, 0, NULL, NULL, post);

    /* check if we're logged */
    if (curl_easy_perform(handle) == CURLE_OK)
    {
       curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
       printf("test done\n");
       printf("the url is %s\n",url);
       //youtube_status = (strstr(url, __YOUTUBE_URL_LOGIN))?0:1;
       printf(" the youtube stattus is %d\n",youtube_status);
    }
    else
      youtube_status = 2;

    curl_easy_cleanup(handle);
  }

  fclose(stream);
  unlink(__FILE_LOGIN);

  return youtube_status;
}

int main(int argc, char *argv[])
{

 int ret=login_perform();

 printf("The return value from the youtube is %d\n", ret);

 return 1;

}

please help me

regards,
bhadraji

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-11-10