static void Main(
string[]
args)
{
string URLAuth = "https://technet.rapaport.com/HTTP/Authenticate.aspx";
WebClient webClient = new
WebClient();
NameValueCollection formData =
new NameValueCollection();
formData["Username"] = "myUser";
formData["Password"] = "myPassword";
byte[] responseBytes = webClient.UploadValues(URLAuth,
"POST", formData);
string ResultAuth = Encoding.UTF8.GetString(responseBytes);
string URL = "http://technet.rapaport.com/HTTP/DLS/GetFile.aspx";
WebRequest webRequest = WebRequest.Create(URL);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
Stream reqStream = webRequest.GetRequestStream();
string postData = "ticket="
+ ResultAuth;
byte[] postArray = Encoding.ASCII.GetBytes(postData);
reqStream.Write(postArray, 0, postArray.Length);
reqStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)
webRequest.GetResponse();;
Stream stream = webResponse.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();
byte [] fileBytes = Encoding.ASCII.GetBytes(content);
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "application/csv";
response.AddHeader("Content-Disposition", "attachment; filename=fileName.csv;");
Response.BinaryWrite(fileBytes);
response.Flush();
response.End();
webResponse.Close();
}