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