<form action="https://www.mywebsite.com/login" method="POST">
<label class="inline" for="remember"></label>
Hi I'm trying to download file from a url which is as below...
https://www.mywebsite.com/mydata/YYYYMMDD/balance_sheet.zip
But It requires a Login (codes are as given below). Is there a way in SSIS Script task that we can implement to Fill up this form and auto submit and get the file downloaded?
<label class="inline" for="remember" style="font-size:0.75em;line-height:1.5;">User Login <input autocomplete="off" autofocus="autofocus" name="username" placeholder="User Login"
tabindex="1" type="text" value="" />Password <input autocomplete="off" name="password" placeholder="Password" tabindex="2" type="password" /></label><label class="inline"
for="remember" style="font-size:0.75em;line-height:1.5;"> </label><input alt="Login" name="login" tabindex="3" type="submit" value="Login" />
<form action="https://www.mywebsite.com/login" method="POST"><p><label class="inline" for="remember"><span></span></label></p><p></p><p><label class="inline" for="remember"><span>User Login</span><!--[endif]----><input autocomplete="off" autofocus="autofocus" name="username" placeholder="User Login" tabindex="1" type="text" value="" /><span>Password</span><!--[endif]----><input autocomplete="off" name="password" placeholder="Password" tabindex="2" type="password" /></label><!--[endif]----><label class="inline" for="remember"></label><input alt="Login" name="login" tabindex="3" type="submit" value="Login" /></p></form>
I tried below code, but it is stuck in Login Page, so basically it is downloading a File with HTML Source code of the Login Page (i.e. Login is getting stuck)
// Function Call
DownLoadFileByWebRequest("https://www.mywebsite.com/mydata/YYYYMMDD/balance_sheet.zip", "D:\\MYLOC\\balance_sheet.zip", "muusername", "mypassword");
//Function
private void DownLoadFileByWebRequest(string urlAddress, string filePath, string username, string password)
{
try
{
System.Net.HttpWebRequest request = null;
System.Net.HttpWebResponse response = null;
string credentials = username + ":" + password;
request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(urlAddress);
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)));
request.PreAuthenticate = true;
request.Timeout = 30000;
response = (System.Net.HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
if (File.Exists(filePath))
{
File.Delete(filePath);
}
FileStream os = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);
byte[] buff = new byte[102400];
int c = 0;
while ((c = s.Read(buff, 0, 1040)) > 0)
{
os.Write(buff, 0, c);
os.Flush();
}
os.Close();
s.Close();
}
catch
{
return;
}
finally
{
}
}
</form>
Regards, Avik M.