471,570 Members | 932 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

Posting data using httpwebrequest.


Hi,

I am trying to develop an interface which will fetch all my Yahoo
mails. I am not able to sign in to yahoo by posting the form with my
username & password. Please find my code below and correct me where am
going wrong.

string result;
System.Net.HttpWebRequest request,request1;
System.Net.HttpWebResponse response,response1;
StreamReader sr;StreamWriter sw;
request1 = (System.Net.HttpWebRequest)
System.Net.WebRequest.Create("http://groups.yahoo.com/");
response1 = (System.Net.HttpWebResponse) request1.GetResponse();
string postData = "login=shansulak_2001&passwd=shansulak";
request =
(HttpWebRequest)System.Net.HttpWebRequest.Create(" http://login.yahoo.com/config/login?.intl=us&.src=ygrp&.done=http://groups.yahoo.com");

request.Method = "POST";
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
Encoding utf8 = new UTF8Encoding();
byte[] content = utf8.GetBytes(postData);
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(content, 0, content.Length);

}
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
Response.Write(result);

Thanks in advance for your help.

Regards,
Shankara.

Feb 17 '06 #1
8 3118
Thus wrote sh*************@gmail.com,
Hi,

I am trying to develop an interface which will fetch all my Yahoo
mails. I am not able to sign in to yahoo by posting the form with my
username & password. Please find my code below and correct me where am
going wrong.

string result;

System.Net.HttpWebRequest request,request1;

System.Net.HttpWebResponse response,response1;

StreamReader sr;StreamWriter sw;

request1 = (System.Net.HttpWebRequest)

System.Net.WebRequest.Create("http://groups.yahoo.com/");

response1 = (System.Net.HttpWebResponse) request1.GetResponse();

string postData = "login=shansulak_2001&passwd=shansulak";

request =

(HttpWebRequest)System.Net.HttpWebRequest.Create(" http://login.yahoo.c
om/config/login?.intl=us&.src=ygrp&.done=http://groups.yahoo.com");

request.Method = "POST";
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
Encoding utf8 = new UTF8Encoding();
byte[] content = utf8.GetBytes(postData);
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(content, 0, content.Length);
}
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
Response.Write(result);
Thanks in advance for your help.


I would assume Yahoo sends a session cookie after successfully logging on.
You need to use a System.Net.CookieContainer instance to keep track of cookies
in your session.
Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Feb 17 '06 #2
You might want to change your account password now that you have just told
everyone what it is.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
<sh*************@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

Hi,

I am trying to develop an interface which will fetch all my Yahoo
mails. I am not able to sign in to yahoo by posting the form with my
username & password. Please find my code below and correct me where am
going wrong.

string result;
System.Net.HttpWebRequest request,request1;
System.Net.HttpWebResponse response,response1;
StreamReader sr;StreamWriter sw;
request1 = (System.Net.HttpWebRequest)
System.Net.WebRequest.Create("http://groups.yahoo.com/");
response1 = (System.Net.HttpWebResponse) request1.GetResponse();
string postData = "login=shansulak_2001&passwd=shansulak";
request =
(HttpWebRequest)System.Net.HttpWebRequest.Create(" http://login.yahoo.com/config/login?.intl=us&.src=ygrp&.done=http://groups.yahoo.com");

request.Method = "POST";
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
Encoding utf8 = new UTF8Encoding();
byte[] content = utf8.GetBytes(postData);
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(content, 0, content.Length);

}
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
Response.Write(result);

Thanks in advance for your help.

Regards,
Shankara.

Feb 17 '06 #3

David wrote:
You might want to change your account password now that you have just told
everyone what it is.

WOW. This was not a wise thing to do.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
<sh*************@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

Hi,

I am trying to develop an interface which will fetch all my Yahoo
mails. I am not able to sign in to yahoo by posting the form with my
username & password. Please find my code below and correct me where am
going wrong.

string result;
System.Net.HttpWebRequest request,request1;
System.Net.HttpWebResponse response,response1;
StreamReader sr;StreamWriter sw;
request1 = (System.Net.HttpWebRequest)
System.Net.WebRequest.Create("http://groups.yahoo.com/");
response1 = (System.Net.HttpWebResponse) request1.GetResponse();
string postData = "login=shansulak_2001&passwd=shansulak";
request =
(HttpWebRequest)System.Net.HttpWebRequest.Create(" http://login.yahoo.com/config/login?.intl=us&.src=ygrp&.done=http://groups.yahoo.com");

request.Method = "POST";
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
Encoding utf8 = new UTF8Encoding();
byte[] content = utf8.GetBytes(postData);
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(content, 0, content.Length);

}
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
Response.Write(result);

Thanks in advance for your help.

Regards,
Shankara.


Feb 17 '06 #4
I have included code for saving cookies. But still not working. Please
Help.

string result;
System.Net.HttpWebRequest request,request1;
System.Net.HttpWebResponse response,response1;
StreamReader sr;StreamWriter sw;
request1 = (System.Net.HttpWebRequest)
System.Net.WebRequest.Create("http://groups.yahoo.com/");
response1 = (System.Net.HttpWebResponse) request1.GetResponse();

string postData = "login=id_for_testing&passwd=testingGroup";
request =
(HttpWebRequest)System.Net.HttpWebRequest.Create(" http://login.yahoo.com/config/login?.intl=us&.src=ygrp&.done=http://groups.yahoo.com");

request.Method = "POST";
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
request.Timeout = 100000;
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(response1.Cookies);
Encoding utf8 = new UTF8Encoding();
byte[] content = utf8.GetBytes(postData);
request.ContentLength = content.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(content, 0, content.Length);
}
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
Response.Write("Server: "+response.Server +" Code:
"+response.StatusCode + " Desc: " + response.StatusDescription);
Response.Write(result);

Thanks & Regards,
Shankara.

Thanks a lot for pointing out that I have leaked out my mail passwd
Dave :-) I have changed it

Feb 20 '06 #5
Thus wrote Shankar,
I have included code for saving cookies. But still not working. Please
Help.

string result;
System.Net.HttpWebRequest request,request1;
System.Net.HttpWebResponse response,response1;
StreamReader sr;StreamWriter sw;
request1 = (System.Net.HttpWebRequest)
System.Net.WebRequest.Create("http://groups.yahoo.com/");
response1 = (System.Net.HttpWebResponse) request1.GetResponse();
string postData = "login=id_for_testing&passwd=testingGroup";

request =

(HttpWebRequest)System.Net.HttpWebRequest.Create(" http://login.yahoo.c
om/config/login?.intl=us&.src=ygrp&.done=http://groups.yahoo.com");

request.Method = "POST";
request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded";
request.Timeout = 100000;
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(response1.Cookies);
CookieContainer tracks cookies automatically. You don't need to copy them
yourself (and at this point, there will be no session cookie, yet).
Encoding utf8 = new UTF8Encoding();
byte[] content = utf8.GetBytes(postData);
request.ContentLength = content.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(content, 0, content.Length);
}
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
result = sr.ReadToEnd();
sr.Close();
Response.Write("Server: "+response.Server +" Code:
"+response.StatusCode + " Desc: " + response.StatusDescription);
Response.Write(result);


So what happens at this point? Do you get redirected back to the login page?
Do you get an error page?

You should also verify that Yahoo uses cookies. I've blindly assumed that,
because it's the most common approach for session tracking, but if they're
using URL rewriting, all of the above won't really help.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Feb 20 '06 #6
Hi Jeorg,

I get a page where it says " The page cannot be found. HTTP 404 - File
not found". I get the Statuscode as "OK" and StatusDescription also
"OK". I am not getting emptystring for response.Server. I think Yahoo
does use cookies. Because, when I donot use the cookie container, it
says, "cookies rejected" error.

Thanks & Regrds,
Shankara.

Feb 21 '06 #7
Sorry. I am getting an emptystring as response for response.Server

Thanks & Regards,
Shankara.

Feb 21 '06 #8
Thus wrote Shankar,
Hi Jeorg,

I get a page where it says " The page cannot be found. HTTP 404 - File
not found". I get the Statuscode as "OK" and StatusDescription also
"OK". I am not getting emptystring for response.Server. I think Yahoo
does use cookies. Because, when I donot use the cookie container, it
says, "cookies rejected" error.


That means you were either redirected to a non-existing page or you requested
a non-existing page.

It's not uncommon that there's no Server header. Many organizations don't
want to reveal what kind of server they are running, due to security concerns.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Feb 21 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by someone | last post: by
1 post views Thread by Isaac Martinez | last post: by
reply views Thread by Jeff Washburn | last post: by
9 posts views Thread by buran | last post: by
7 posts views Thread by Mark Waser | last post: by
reply views Thread by msnews.microsoft.com | last post: by
2 posts views Thread by adwooley2 | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.