
March 5th, 2003, 07:06 PM
|
|
Registered User
|
|
Join Date: Mar 2003
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
HttpWebRequest and Querystring
I am using the httpwebrequest class to scape data from a webpage. If I do not include any name/vale pairs in the link, I get the default data, which is today's data with today's date. Now, if I want to get data from another day, I need to pass 'marketdate=2003-03-03' (in this case I would get Mar 3rd data) as the querystring. When I pass this as the link (include the querystring in the link) OR if I get a stream writer to 'write' it, it is ignored. If I enter the link into my web browser (IE6), it ignores the querystring as well, until I refresh. Once I do this, the proper date pulls up. <br><br>The name 'marketdate' is correct - I have made sure of that. My question is, how do either get my httpwebrequest object to successfully pass thge querystring, or how do I mimick the behavior of IE6 (as mentioned above)? My thought was to some how open a connection (thru the socket class?) and keep that connection open while I pass the querystring to it. <br><br>Anyone got any ideas or run into anythign similar? <br><br>Here is my code as it stands now: <br><br>'create web request to get the webpage with data <br>Dim sLink As String <br><br>sLink = "http://somesite.com/jsp/somedata.jsp" <br>Dim sQuery As New System.Text.StringBuilder() <br><br>sQuery.Append("marketdate=2003-03-03") <br><br>Dim req As HttpWebRequest = WebRequest.Create(sLink) <br><br>'must use x509 certificate to connect <br>'req.ClientCertificates.Add(X509Certificate.Create FromCertFile("C:X509.cer")) <br>req.ContentType = "application/x-www-form-urlencoded" <br>req.Method = "POST" <br>req.ContentLength = sQuery.Length <br><br>Dim w As StreamWriter = New StreamWriter(req.GetRequestStream) <br>w.Write(sQuery.ToString) <br>w.Close() <br><br>Dim r As HttpWebResponse = req.GetResponse <br><br>'get webpage with data <br>Dim reader As New StreamReader(r.GetResponseStream) <br><br>'dump the webpage into a string variable <br>Dim x As String = reader.ReadToEnd <br><br>'write out to file for parsing <br>Dim writer As New StreamWriter("C:stuff.txt") <br>writer.Write(x) <br>writer.Flush() <br>writer.Close() <br><br>Any help would be appreciated! <br><br>Thanks!
|