Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2007, 04:04 AM
Registered User
 
Join Date: Dec 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default can not login automatically

Hi
Please help, I write code using HttpWebRequest and HttpWebResponse to login to yahoo mail but it was not successful. It displays the login form page only. Please let me know what is wrong with it. Here is my code:

using System;
using System.Net;
using System.IO;
using System.Text;

namespace WebDavNET
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
        static void Main(string[] args)
        {
            string strLoginName = //my username here
            string strPassword = //my passwd here
            string retStr = "", tempStr = "";
            HttpWebResponse webRespResult = null;

           try
            {
                string strURL = "http://login.yahoo.com/config/login?";
                string strPostData = String.Format("login={0}&passwd={1}",
                                     strLoginName, strPassword);

                HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(strURL);
                webReq.Method = "POST";
                webReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)";
                webReq.ContentType = "application/x-www-form-urlencoded";
                // webReq.Proxy = WebProxy.GetDefaultProxy(); // does not work any more
                webReq.ContentLength = strPostData.Length;
                webReq.KeepAlive = true;

                ASCIIEncoding encoding = new ASCIIEncoding();

                Byte[] bytes = encoding.GetBytes(strPostData);

                webReq.ContentType = "application/x-www-form-urlencoded";

                webReq.ContentLength = strPostData.Length;

                Stream inputStream = webReq.GetRequestStream();
                inputStream.Write(bytes, 0, bytes.Length);
                inputStream.Close();

                webRespResult = (HttpWebResponse)webReq.GetResponse();

                Stream ReceiveStream = webRespResult.GetResponseStream();
                Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                StreamReader streamRead = new StreamReader(ReceiveStream, encode);
                Char[] read = new Char[256];
                int count = streamRead.Read(read, 0, 256);

                while (count > 0)
                {
                    tempStr = new String(read, 0, count);
                    retStr += tempStr;
                    count = streamRead.Read(read, 0, 256);
                }
                retStr.Trim();
                Console.WriteLine(retStr);
                Console.ReadLine();

            }
            catch (WebException e)
            {
                Console.WriteLine("\nMain 1 Exception raised!");
                Console.WriteLine("\nMessage 1:{0}", e.Message);
                Console.WriteLine("\nStatus 1:{0}", e.Status);
                Console.WriteLine("Press any key to conntinue..........");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("\nMain 2 Exception raised!");
                Console.WriteLine("Source 2:{0} ", e.Source);
                Console.WriteLine("Message 2:{0} ", e.Message);
                Console.WriteLine("Press key to continue..........");
                Console.ReadLine();
            }

            finally
            {
                if (webRespResult != null)
                {
                    webRespResult.Close();
                }
            }

        }
    }
}
 
Old December 19th, 2007, 02:11 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by lukemai
 It displays the login form page only.

What is "it"? You are writing a console page, so what is showing the login page?

Is it possible the problem here is that the URL you are using auto redirects to HTTPS? Could you explain your final goal? You are writing a console app, but it is not clear what you are intending to do with the result of logging in automatically with this code.

-Peter
 
Old December 19th, 2007, 02:42 PM
Registered User
 
Join Date: Dec 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi planoie
I use the consol so that when I run the code in .exe file, It will go the the selected website and login by username and password that I have, and then get the info. from selected event.
Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
login script: user can't hit "return" for login dmerrill Java Basics 13 July 14th, 2006 07:25 PM
Newbie Help. Login to unique login page per user Kainan Classic ASP Professional 10 May 3rd, 2005 07:47 AM
login failed for user nt authority\anonymous login rj1406 Classic ASP Databases 1 October 24th, 2004 09:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.