Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 135,959 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,600 people online right now. Registration is fast and FREE... Join Now!




Automatic Website Data Grabber

 
Reply to this topicStart new topic

Automatic Website Data Grabber

tody4me
23 May, 2008 - 11:58 AM
Post #1

Only Jenny Craig makes thin clients...
Group Icon

Joined: 12 Apr, 2006
Posts: 1,278



Thanked: 3 times
Dream Kudos: 100
My Contributions
I've been working on this project for a while, to no avail. The code looks and seems like it should work, but for some reason it's not posting to the site correctly I'm guessing and I don't know if it's because I'm not passing the variable names correctly or what. I figured another set of eyes would help right about now so here goes.
I'm working on an extension to a program that I have that uploads and downloads data about orders / customers. Right now the way it works is that someone goes out to a site to get the current data from a vendor, then another set of data is stored on the network, and all of this is updated daily and reports are generated. The one vendor has a site that I go to in order to get some data from, this is a manual process that I'm wanting to speed up. For some reason the credentials are not processing correctly, and I don't know why. Here's some code

CODE

            CookieContainer cookie = new CookieContainer();
            string pageData = string.Empty;
            StreamReader respReader = null;

            label1.Text = "Finding Site ...";
            Application.DoEvents();
            _mainRequest = (HttpWebRequest) WebRequest.Create(LOGIN_SITE);
            label1.Text = "Setting Parameters";
            Application.DoEvents();
            _mainRequest.Method = "POST";
            _mainRequest.ContentType = "application/x-www-form-urlencoded";
            _mainRequest.CookieContainer = cookie;

            label1.Text = "Building String to Send";
            Application.DoEvents();
            StreamWriter reqWriter = new StreamWriter(_mainRequest.GetRequestStream());
            label1.Text = "Sending Form data";
            Application.DoEvents();
            reqWriter.Write(string.Format("__VIEWSTATE={0}&Username={1}&cPassword={2}&Login=Login",
                viewState, userID, password));
            reqWriter.Close();

            label1.Text = "Closing Response from Site";
            Application.DoEvents();

            _mainRequest.GetResponse().Close();
            //respReader = new StreamReader(_mainRequest.GetResponse().GetResponseStream());
            //pageData = respReader.ReadToEnd();
            //respReader.Close();
            //textBox1.Text = pageData;
            //return false;

            label1.Text = "Looking up secure Site";
            Application.DoEvents();
            _mainRequest = (HttpWebRequest) WebRequest.Create(DATA_PAGE1);
            _mainRequest.CookieContainer = cookie;
            label1.Text = "Getting Response from Site";
            Application.DoEvents();
            respReader = new StreamReader(_mainRequest.GetResponse().GetResponseStream());
            pageData = respReader.ReadToEnd();
            label1.Text = "Cleaning up";
            Application.DoEvents();
            respReader.Close();
            label1.Text = "Ready";
            textBox1.Text = pageData;
            Application.DoEvents();
            return true;


the commented code is testing code that I used once to try to test a section of code was working.

This post has been edited by tody4me: 23 May, 2008 - 11:58 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 09:22AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month