Here's what happens, I send a request, and reading the response, I get and parse out what would become the session cookie if I were to use a Browser. It looks something like this to get my first response:
Expand|Select|Wrap|Line Numbers
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create( loginUri );
- request.CookieContainer = new CookieContainer();
- string data = "login=" + loginName + "&key=" + password + "&button1=click";
- byte[] buffer = Encoding.UTF8.GetBytes( data );
- // Tell the request that we are going to answer
- request.Method = "POST";
- request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10";
- request.KeepAlive = true;
- request.ContentLength = data.Length;
- // Get the response stream and add our login information
- Stream uploadPackage = request.GetRequestStream();
- uploadPackage.Write( buffer, 0, buffer.Length );
- // Send the data by means of .Flush()
- uploadPackage.Flush();
- // Close the stream
- uploadPackage.Close();
- Stream responseStream = response.GetResponseStream();
- StreamReader sr = new StreamReader( responseStream );
- string loginResult = string.Empty;
- if ( !sr.EndOfStream )
- loginResult = sr.ReadToEnd();
Expand|Select|Wrap|Line Numbers
- <SCRIPT type="text/JavaScript">
- document.cookie="KEY=12345; path=/;";
- document.cookie=";";
- if ("".length > 0) {
- document.cookie=";";
- }
- if ("".length > 0) {
- document.cookie=";";
- }
- if ("".length > 0) {
- document.cookie=";";
- }
- if ("".length > 0) {
- location.assign("");
- }
- </SCRIPT>
Expand|Select|Wrap|Line Numbers
- HttpWebRequest uploadRequest = HttpWebRequest)WebRequest.Create( uploadUri );
- // put the previous cookie into this request
- uploadRequest.CookieContainer = ???????;