473,508 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebRequest to login youtube

5 New Member
After bunch of searching on google I end up with posting new thread for help,

I am trying to login to youtube using webRequest/Response but no success, it is returning source code which tells that "Your browser cookies disabled ..." etc.

Attaching my code and can someone tell me the solution or if any better way to do this ?

I know that youtube api offer these function but I've to do without api for my project.

here is my source code

Expand|Select|Wrap|Line Numbers
  1. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  2.                 CookieContainer container = new CookieContainer();
  3.                 request.CookieContainer = container;
  4.  
  5.                 StreamReader reader;
  6.                 Stream stream;
  7.  
  8.                 using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  9.                 {
  10.                     response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);
  11.                     stream = response.GetResponseStream();
  12.                     reader = new StreamReader(stream);
  13.  
  14.                     string temp1 = reader.ReadToEnd();
  15.                     richTextBox1.Text = temp1;
  16.  
  17.                     String Pattern = "name=\"GALX\"[\\s]*value=\"([a-zA-Z0-9-_\\.]*)\"";
  18.                     galx = richTextBox1.Text;
  19.                     Match myMatch = Regex.Match(galx, Pattern);
  20.                     galx = myMatch.Groups[1].ToString();
  21.  
  22.                     string url2 = "https://www.google.com/accounts/ServiceLoginAuth?service=youtube&ltmpl=sso&continu e=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_h andle_signin%3Dtrue%26nomobiletemp%3D1%26hl%3Den_U S%26next%3D%252F&service=youtube&uilel=3&ltmpl=sso &hl=en_US&ltmpl=sso&GALX=" + galx + "&Email=username&Passwd=password&rm Shown=1&signIn=Sign+in&asts=";
  23.  
  24.                     richTextBox1.Text = "";
  25.  
  26.                     HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(url2);
  27.                     request2.CookieContainer = container;
  28.                     request2.Method = "POST";
  29.                     request2.Referer = "https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true& continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Fa ction_handle_signin%3Dtrue%26nomobiletemp%3D1%26hl %3Den_US%26next%3D%252F&hl=en_US&ltmpl=sso";
  30.                     request2.MaximumAutomaticRedirections = 50;                    
  31.                     request2.AllowAutoRedirect = true;
  32.                     request2.KeepAlive = true;
  33.                     request2.ContentLength = 0;
  34.                     container = request2.CookieContainer;
  35.  
  36.                     HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();
  37.                     response2.Cookies = request2.CookieContainer.GetCookies(request2.RequestUri);
  38.  
  39.  
  40.                     Stream responseStream = response2.GetResponseStream();
  41.                     response2.Cookies = request2.CookieContainer.GetCookies(request2.RequestUri);
  42.                     request2.CookieContainer = container;
  43.  
  44.                     StreamReader ressponseReader = new StreamReader(response2.GetResponseStream());
  45.  
  46.                     string temp;
  47.                     temp = ressponseReader.ReadToEnd().ToString();
  48.                     richTextBox2.Text += temp;
  49.  
  50.  
  51.  
Jan 3 '12 #1
5 5932
johny10151981
1,059 Top Contributor
When returned code says your browser dont support cookie it means, you are not sending cookie back to the server.

in fact when server get a log in request it also look for previously set cookie. so make sure you are sending back those cookie that is send by google. And one thing, there is no special log in for youtube all google use the same login info.
Jan 4 '12 #2
buynsell
5 New Member
hey thnx for the reply,

I guess I am sending back cookies already here,
Expand|Select|Wrap|Line Numbers
  1. request2.CookieContainer = container; 
can you please be more specific how to send cookie back if not like this, I am not very good at this httpwebrequest/response,

I already tried alot googling but still no success !!!
Stuck badly
Jan 4 '12 #3
johny10151981
1,059 Top Contributor
did you check whether container is empty or what?
Jan 5 '12 #4
buynsell
5 New Member
no container isn't empty, when I checked its count that is 5.
Jan 5 '12 #5
webmarketing
1 New Member
I think other site proprietors should take blog.blackhc.net as an model, very clean and excellent user friendly style and design, let alone the content. You are an expert in this topic!
Jan 17 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2305
by: Gill Bates | last post by:
I'm trying to login to a banking site (https://www.providentconnection.com) using vb.net. I've tried many variations of WebClient and HttpWebRequest; none of which I've got to work. My latest...
6
3071
by: omyek | last post by:
I'm trying to mimic the browsing of a webpage using an HttpWebRequest. I've had a lot of luck with it so far, including logging into pages, posting form data, and even collecting and using cookies....
1
7865
by: Tom Jones | last post by:
Hi, I am using the HttpWebRequest and HttpWebResponse classes to pull information from a web server on the internet. I have an account on one of the webservers that I need to log into...
0
2466
by: love_norip | last post by:
I have encountered a problem when I try to visit a web page (like http://www.xxx.org....?arg1=x&arg2=x&....) using HttpWebRequest and HttpWebResponse and related methods .NET provides.The code is...
1
1453
by: PokerJoker | last post by:
My company has a third party purchased website that we use to allow clients to log in and view/modify orders in our system. It has its own login page, but I would like to add a form to my...
2
5558
by: adwooley2 | last post by:
Hello. Have been losing plenty of hair over problem whereby I can't make it off the login page. Trying to pass login info to a login page and then move on to another page within the site so that...
6
3319
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
1
1986
by: twebb72 | last post by:
Scratching my head for a while on this one... This project uses code from "Understanding HttpWebRequest CookieContainer?" post on this site. C#, asp.net 2.0 The following code supplies...
5
3176
by: mcfly1204 | last post by:
I am attempting to use WebRequest to access a page that requires a login/password to access. My last WebRequest continues to timeout. Any help or thoughts would be appreciated. namespace...
16
16627
by: GVNPublic123 | last post by:
Hello, What I am trying to do, is login YouTube using C# (HTTPWebRequest). The problem is, I don't really know how to do it. Is there any URL I could fill using the username and pass and...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.