Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Guidance for HTTPWebRequest and HTTPWebResponse
Message
From
11/11/2004 11:42:54
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00960251
Message ID:
00960487
Views:
10
Hi, Hector-

Thanks for your continued interest.

>I took a quick look at the page that you are working on. It seems that the button calls a javascript function called navigate that is defined on their "common.js" file.
>
>You can download their javascript file from https://fortress.wa.gov/dol/ddl/dsd/Inc/common.js and take a look at what the navigate function does.

Yes. I spent last night working on this, and found the common.js file and have tried a number of things, all of which have failed. Specifically, I've looked at the HTML source at each step and then tried inserting the hidden values into the stream. I am possibly just confusing which values need to be inserted in which stream. Unfortunately hitting the first page fails right off in some javascript that checks the screen width. I think that's in the header.

I can hit the login page, but none of the values I set get passed through. (I've run Rick's sample to make sure I can do at least that, and I can.) So, possibly that page is resetting values, I'm not sure. I wanted to try and read small amounts and insert the values into the stream at the end, but the stream is writable, but not readable or seekable.

I don't believe the webserver disallows POST methods, because I tried hitting my client's site and get back a very specific error message (POST is disallowed on our server). So, I *think* the POST works, but I'm not even sure about that. :-(

>The navigate function seems call the validatefields function defined on the page which in turn sets the values of two hidden fields and then submit the page to the server. I imagine that once the page is posted back the server notices the values of these hidden fields and does some extra processing (e.g. validate the license and redirect you to a different page to display the results of the validation.)

Right. Which makes me think that the values get inserted at the beginning, then are reset. But this is all new to me so of course am still unclear on the sequence of events.

>>The problem I'm having is the buttons don't just obviously
>> naviage to a page.
>
>You are right, it seems that they post back this same form and then the server decides to navigate to a different form based on the values of the hidden fields.

Right.

>> The page that you end up on if you
>> click through won't allow a direct hit.
>
>That's usually the case. I've found that most of the times is better to hit the page that users hit and just emulate all the values that a user would enter so that the request looks exactly like if a person actually hit the page.

I'll work on it some more this morning. Hopefully a fresh eye will help. Thanks for commenting. I really appreciate it.

FWIW, the following is the current state of my test code (I've simplified the values to one, just to see if I can succeed there):
		[STAThread]
		static void Main(string[] args)
		{

			string hiddenInputs = 
				"hdnSkipPut=\"" + HttpUtility.UrlEncode("1") + "\"";
				
				/*				
				"hdnSkipPut=\"" + HttpUtility.UrlEncode("1") + "\"";
				"&hdnRequestNum=\"" + HttpUtility.UrlEncode("") + "\"" +
								"&hdnAppCode=\"" + HttpUtility.UrlEncode("DSD") + "\"" +
								"&hdnSessionID=\"" + HttpUtility.UrlEncode("") + "\"" +
								"&hdnSessionIPAddress=\"" + HttpUtility.UrlEncode("") + "\"" +
								"&hdnSessionPIC=\"" + HttpUtility.UrlEncode("") + "\"" +
								"&hdnScreen=\"" + HttpUtility.UrlEncode("INIT") + "\"" +
								"&hdnScreenName=\"" + HttpUtility.UrlEncode("Initial Instructions") + "\"" +
								"&hdnNextScreen=\"" + HttpUtility.UrlEncode("F") + "\"" +
								"&hdnURL=\"" + HttpUtility.UrlEncode("ApplicationLogin") + "\"" +
								"&hdnIsScreenComp=\"" + HttpUtility.UrlEncode("") + "\"" +
								"&hdnBypass=\"" + HttpUtility.UrlEncode("") + "\"" +
								"&hdnDate=\"" + HttpUtility.UrlEncode("") + "\"" +
								"&hdnIndependent=\"" + HttpUtility.UrlEncode("1") + "\"" +
								"&hdnBrowserType=\"" + HttpUtility.UrlEncode("IE") + "\"" +
								"&hdnBrowserVersion=\"" + HttpUtility.UrlEncode("6") + "\"" +
								"&hdnSysDemoFlag=\"" + HttpUtility.UrlEncode("") + "\"" +
								"&hdnScreenStatusID=\"" + HttpUtility.UrlEncode("") + "\"" +
								"&hdnSystemDate=\"" + HttpUtility.UrlEncode("") + "\"" + 
								"&ACTION=" + HttpUtility.UrlEncode("Main2.ASP");
				*/

			ASCIIEncoding encoder = new ASCIIEncoding();
			byte[] postBytes = encoder.GetBytes(hiddenInputs);

			HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://fortress.wa.gov/dol/ddl/dsd/Default.asp");
			webRequest.Method="POST";
			webRequest.ContentLength = postBytes.Length;

			// TODO: Necessary or not? Look up "ContentType"
			// webRequest.ContentType = "application/x-www-form-urlencoded";

			Stream stream = webRequest.GetRequestStream();
			stream.Write(postBytes,0,postBytes.Length);
			stream.Close();
			HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse();

			// Console.WriteLine(webResponse.ResponseUri.ToString());
			
			StreamReader streamReader = new StreamReader(webResponse.GetResponseStream());
			StreamWriter streamWriter = new StreamWriter("My.HTML");
			string html = streamReader.ReadToEnd();
			streamWriter.Write(html);
			streamWriter.Close();
			streamReader.Close();
		}
	}
Previous
Reply
Map
View

Click here to load this message in the networking platform