.net way for HTTP form POST with redirection/navigation?
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-io' list.


Aaron Kaufman
I've been doing screen scraping in .net for some time. I have a need to actually post data with the .net API along with a redirection to that page. I will be redirecting from an ASP.net site to an ASP site that requires a login. The data will be a form post to the ASP site with the user name and password. I found the old school way to do this.
How would I go about doing this via the ASP.net API?
http://abstractvb.com/code.asp?F=136&P=1&A=948

---------------------------------
Do You Yahoo!?
Sign-up for Video Highlights of 2002 FIFA World Cup
Reply to this message...
 
    
Peter Brunone
Aaron,

    Head on over to AspAlliance.com for a great collaboration by Alex Lowe and
Steve Smith. It's pretty simple as complex functions go; you should be able
to implement it with no problems, but -- as you know -- come back if you
have questions.

    The article: http://www.aspalliance.com/stevesmith/articles/netscrape2.asp

Cheers,

Peter Brunone
AspFriends.com Moderation Team
Microsoft MVP, ASP.NET

|-----Original Message-----
|From: Aaron Kaufman [mailto:Click here to reveal e-mail address]
|
|I've been doing screen scraping in .net for some time. I have a
|need to actually post data with the .net API along with a
|redirection to that page. I will be redirecting from an ASP.net
|site to an ASP site that requires a login. The data will be a
|form post to the ASP site with the user name and password. I
|found the old school way to do this.
|How would I go about doing this via the ASP.net API?
| http://abstractvb.com/code.asp?F=136&P=1&A=948
|

Reply to this message...
 
    
Alex Lowe
I also wrote an article (that appeared in the June issue of asp.netPRO
magazine) about screen scraping. It details an alternative way of screen
scraping using GET, POST, and authenticating against a site with BASIC
authentication enabled. You might want to check that article out at
(http://www.aspnetpro.com/features/2002/06/asp200206al_f/asp200206al_f.a
sp) - it's free.

Hth,

Alex - AspFriends.com Moderation Team
Microsoft MVP - ASP.NET

***********************************************************
Translate C# code to VB.NET code at
http://aspalliance.com/aldotnet/examples/translate.aspx
***********************************************************

[Original message clipped]

Reply to this message...
 
    
Aaron Kaufman
Please re-read my post. I am already doing screen scraping. I need to post to a page with a navigation to that page. For example, when they click on the link from my portal it will take them to their yahoo mail logged in. I actually want them to leave my portal.
Peter Brunone <Click here to reveal e-mail address> wrote: Aaron,

Head on over to AspAlliance.com for a great collaboration by Alex Lowe and
Steve Smith. It's pretty simple as complex functions go; you should be able
to implement it with no problems, but -- as you know -- come back if you
have questions.

The article: http://www.aspalliance.com/stevesmith/articles/netscrape2.asp

Cheers,

Peter Brunone
AspFriends.com Moderation Team
Microsoft MVP, ASP.NET

|-----Original Message-----
|From: Aaron Kaufman [mailto:Click here to reveal e-mail address]
|
|I've been doing screen scraping in .net for some time. I have a
|need to actually post data with the .net API along with a
|redirection to that page. I will be redirecting from an ASP.net
|site to an ASP site that requires a login. The data will be a
|form post to the ASP site with the user name and password. I
|found the old school way to do this.
|How would I go about doing this via the ASP.net API?
| http://abstractvb.com/code.asp?F=136&P=1&A=948
|

| [ngfx-io] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-io.asp = JOIN/QUIT

---------------------------------
Do You Yahoo!?
Sign-up for Video Highlights of 2002 FIFA World Cup
Reply to this message...
 
    
Alex Lowe
Aaron,

In most cases, you will need to skip the screen where you would enter
the username/password and post directly to the screen responsible for
processing the username/password. I guess I still don't understand the
scenario you are referring to.

Alex - AspFriends.com Moderation Team
Microsoft MVP - ASP.NET

***********************************************************
Translate C# code to VB.NET code at
http://aspalliance.com/aldotnet/examples/translate.aspx
***********************************************************

-----Original Message-----
From: Aaron Kaufman [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 06, 2002 8:14 AM
To: ngfx-io
Subject: [ngfx-io] RE: .net way for HTTP form POST with
redirection/navigation?

Please re-read my post. I am already doing screen scraping. I need to
post to a page with a navigation to that page. For example, when they
click on the link from my portal it will take them to their yahoo mail
logged in. I actually want them to leave my portal.
Peter Brunone <Click here to reveal e-mail address> wrote:
Aaron,

Head on over to AspAlliance.com for a great collaboration by Alex Lowe
and
Steve Smith. It's pretty simple as complex functions go; you should be
able
to implement it with no problems, but -- as you know -- come back if you
have questions.

The article:
http://www.aspalliance.com/stevesmith/articles/netscrape2.asp

Cheers,

Peter Brunone
AspFriends.com Moderation Team
Microsoft MVP, ASP.NET

|-----Original Message-----
|From: Aaron Kaufman [mailto:Click here to reveal e-mail address]
|
|I've been doing screen scraping in .net for some time. I have a
|need to actually post data with the .net API along with a
|redirection to that page. I will be redirecting from an ASP.net
|site to an ASP site that requires a login. The data will be a
|form post to the ASP site with the user name and password. I
|found the old school way to do this.
|How would I go about doiSign-up for Video Highlights of 2002 FIFA World
Cup | [ngfx-io] member Click here to reveal e-mail address = YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-io.asp = JOIN/QUIT

Reply to this message...
 
    
Travis McGee
Peter,

Here is an example application that I have to do what you are asking.
This one is activated by Page_Load, but you could do it with another
event. Also, with this, I am only accepting the string data, but you
can also grab the entire page as well. And, it does handle keeping a
session via cookie acceptance/response. Let me know if you need more
explanation.

Travis McGee

The basis for this was taken from a kind author at ASPAlliance.com with
modifications by myself to handle session maintenance between this
application and the web server.

using System;
using System.Net;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ScapeME
{
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class ScrapeForm : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Literal myPage;
    
        private void Page_Load(object sender, System.EventArgs
e)
        {
            myPage.Text = readHtmlPage("FULL URL TO THE
LOGON FORM HERE");
        }

        private String readHtmlPage(string url)
        {
            String result = "";
            String strPost = "POST DATA GOES HERE LIKE
somethin=something&somethingelse=somethingelse";
            StreamWriter myWriter = null;

            HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create(url);
            objRequest.CookieContainer = new
CookieContainer();
            objRequest.Method = "POST";
            objRequest.ContentLength = strPost.Length;
            objRequest.ContentType =
"application/x-www-form-urlencoded";

            try
            {
                myWriter = new
StreamWriter(objRequest.GetRequestStream());
                myWriter.Write(strPost);
            }
            catch (Exception e)
            {
                return e.Message;
            }
            finally
            {
                myWriter.Close();
            }

            HttpWebResponse objResponse =
(HttpWebResponse)objRequest.GetResponse();
            CookieCollection cookies = objResponse.Cookies;
            using (StreamReader sr =
                     new
StreamReader(objResponse.GetResponseStream()) )
            {
                result = sr.ReadToEnd();

                // Close and clean up the StreamReader
                sr.Close();
            }
            return result;
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET
Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new
System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}

-----Original Message-----
From: Alex Lowe [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 06, 2002 5:53 AM
To: ngfx-io
Subject: [ngfx-io] RE: .net way for HTTP form POST with
redirection/navigation?

Aaron,

In most cases, you will need to skip the screen where you would enter
the username/password and post directly to the screen responsible for
processing the username/password. I guess I still don't understand the
scenario you are referring to.

Alex - AspFriends.com Moderation Team
Microsoft MVP - ASP.NET

***********************************************************
Translate C# code to VB.NET code at
http://aspalliance.com/aldotnet/examples/translate.aspx
***********************************************************

-----Original Message-----
From: Aaron Kaufman [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 06, 2002 8:14 AM
To: ngfx-io
Subject: [ngfx-io] RE: .net way for HTTP form POST with
redirection/navigation?

Please re-read my post. I am already doing screen scraping. I need to
post to a page with a navigation to that page. For example, when they
click on the link from my portal it will take them to their yahoo mail
logged in. I actually want them to leave my portal.
Peter Brunone <Click here to reveal e-mail address> wrote:
Aaron,

Head on over to AspAlliance.com for a great collaboration by Alex Lowe
and Steve Smith. It's pretty simple as complex functions go; you should
be able to implement it with no problems, but -- as you know -- come
back if you have questions.

The article:
http://www.aspalliance.com/stevesmith/articles/netscrape2.asp

Cheers,

Peter Brunone
AspFriends.com Moderation Team
Microsoft MVP, ASP.NET

|-----Original Message-----
|From: Aaron Kaufman [mailto:Click here to reveal e-mail address]
|
|I've been doing screen scraping in .net for some time. I have a need to

|actually post data with the .net API along with a redirection to that
|page. I will be redirecting from an ASP.net site to an ASP site that
|requires a login. The data will be a form post to the ASP site with the

|user name and password. I found the old school way to do this.
|How would I go about doiSign-up for Video Highlights of 2002 FIFA World
Cup | [ngfx-io] member Click here to reveal e-mail address = YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-io.asp = JOIN/QUIT

| [ngfx-io] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-io.asp = JOIN/QUIT

Reply to this message...
 
    
Aaron Kaufman
Alex,
I would like to progamatically post username and password to the 'action' page along with the user being redirected there as well. I do not want to scrape that page. I would actually like to go there logged in from a single link click from my portal. Similar to what yodlee.com does, but without all the fancy javascript. In yodlee you can click on your bank account and the application takes you to 'Citibank.com' logged in. I already have the username and passwords for these features. Just need a methodology on how to do it with .Net.
Aaron
Alex Lowe <Click here to reveal e-mail address> wrote: Aaron,

In most cases, you will need to skip the screen where you would enter
the username/password and post directly to the screen responsible for
processing the username/password. I guess I still don't understand the
scenario you are referring to.

Alex - AspFriends.com Moderation Team
Microsoft MVP - ASP.NET

***********************************************************
Translate C# code to VB.NET code at
http://aspalliance.com/aldotnet/examples/translate.aspx
***********************************************************

-----Original Message-----
From: Aaron Kaufman [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 06, 2002 8:14 AM
To: ngfx-io
Subject: [ngfx-io] RE: .net way for HTTP form POST with
redirection/navigation?

Please re-read my post. I am already doing screen scraping. I need to
post to a page with a navigation to that page. For example, when they
click on the link from my portal it will take them to their yahoo mail
logged in. I actually want them to leave my portal.
Peter Brunone
wrote:
Aaron,

Head on over to AspAlliance.com for a great collaboration by Alex Lowe
and
Steve Smith. It's pretty simple as complex functions go; you should be
able
to implement it with no problems, but -- as you know -- come back if you
have questions.

The article:
http://www.aspalliance.com/stevesmith/articles/netscrape2.asp

Cheers,

Peter Brunone
AspFriends.com Moderation Team
Microsoft MVP, ASP.NET

|-----Original Message-----
|From: Aaron Kaufman [mailto:Click here to reveal e-mail address]
|
|I've been doing screen scraping in .net for some time. I have a
|need to actually post data with the .net API along with a
|redirection to that page. I will be redirecting from an ASP.net
|site to an ASP site that requires a login. The data will be a
|form post to the ASP site with the user name and password. I
|found the old school way to do this.
|How would I go about doiSign-up for Video Highlights of 2002 FIFA World
Cup | [ngfx-io] member Click here to reveal e-mail address = YOUR ID |
http://www.aspfriends.com/aspfriends/ngfx-io.asp = JOIN/QUIT

| [ngfx-io] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-io.asp = JOIN/QUIT

---------------------------------
Do You Yahoo!?
Sign-up for Video Highlights of 2002 FIFA World Cup
Reply to this message...
 
 
System.EventArgs
System.EventHandler
System.IO.StreamReader
System.IO.StreamWriter
System.Net.CookieCollection
System.Net.CookieContainer
System.Net.HttpWebRequest
System.Net.HttpWebResponse
System.Net.WebRequest
System.Web.UI.Page
System.Web.UI.WebControls.Literal




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com