for long file you can use this :
string URLAuth = "https://technet.rapaport.com/HTTP/Authenticate.aspx"; WebClient webClient = new WebClient(); NameValueCollection formData = new NameValueCollection(); formData["Username"] = "XXX"; formData["Password"] = "YYY"; byte[] responseBytes = webClient.UploadValues(URLAuth, "POST", formData); string ResultAuth = Encoding.UTF8.GetString(responseBytes); //After receiving an encrypted ticket, you can use it to authenticate your session. //Now you can choose to change the protocol to HTTP so it works faster. //Download File 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); // for long files List<string> list = new List<string>(); string line; while ((line = reader.ReadLine()) != null) { list.Add(line); // Add to list. } File.AppendAllLines(@"C:\\test\\MyFile.csv", list);
|