How to Download a text file after loging into a web server ?

Jan 17 2007 1:05 AM

Hi this is my first post. I am trying to Download a text file after logging into a https server using post method. I get log in and after that is a huge ? mark.


using
System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace Logon
{
public class Autologger
{
public static void Main(string[] args)
{
HttpWebRequest httpRequest;
HttpWebRequest httpFileRequest;
HttpWebResponse httpResponse;
HttpWebResponse httpFileResponse;
StreamReader bodyReader;
Stream responseStream;
Stream requestStream;
char[] buffer = new char[500];
httpRequest = (
HttpWebRequest) WebRequest.Create(https://blabla.bla/bla.jsp);  //I have changed the name of the url
string postData = "username=username&password=password";
httpRequest.Method =
"POST";
httpRequest.ContentType =
"application/x-www-form-urlencoded";
httpRequest.ContentLength = postData.Length;
httpRequest.AllowAutoRedirect =
true;
requestStream = httpRequest.GetRequestStream();
requestStream.Write(
Encoding.ASCII.GetBytes(postData), 0, postData.Length);
requestStream.Close();
httpResponse = (
HttpWebResponse)httpRequest.GetResponse();
responseStream = httpResponse.GetResponseStream();
bodyReader =
new StreamReader(responseStream);

bodyReader.ReadLine();//The webpage got in resposnse on the 3rd line has the authorization key that is required to be tagged along to get the url of the txt file to be downloaded.
bodyReader.ReadLine();
string[] temp = null;
string bodyText = bodyReader.ReadLine().ToString();

authorizationKey = bodyText.Split(new char[3] { ' ',',','\'' });
httpFileRequest = (HttpWebRequest)WebRequest.Create(@"http://blabla.bla/bla.jsp?authtoken=" + authorizationKey [authorizationKey .Length - 2] + "&authsilent=1&retrieve=c:\tps\logs\tps\MCC-Usage20070114.log");

Console.Read();

}


}

}

I get my authorization key to form my url after that I have tried changing the uri of httpRequest but the property is read only for Address.
Can anyone help me out with this.

Thank you