13 Replies - 4253 Views - Last Post: 14 March 2012 - 07:38 AM
#1 Guest_Andrew*
How to automate a login into a jsp site to download a file
Posted 14 October 2010 - 12:02 PM
Replies To: How to automate a login into a jsp site to download a file
#2
Re: How to automate a login into a jsp site to download a file
Posted 14 October 2010 - 12:11 PM
#3 Guest_Andrew*
Re: How to automate a login into a jsp site to download a file
Posted 14 October 2010 - 12:20 PM
private void Web()
{
WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
wb.Navigate("http://www.supplierlink.carrier.com");
}
private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string username = "username";
string password = "password";
WebBrowser web = sender as WebBrowser;
HtmlElement usernameElement = web.document.GetElementById("USER");
usernameElement.InnerText = username;
HtmlElement passwordElement = web.document.GetElementById("Password");
passwordElement.InnerText = password;
web.document.GetElementById("submit").InvokeMember("click");
}
private void wb_DocumentCompleted2(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser b = sender as WebBrowser;
string response = b.DocumentText;
StreamWriter sw = new StreamWriter(@"C:\Users\azwicker\Desktop\text.txt");
sw.Write(response);
sw.Close();
if (response.Contains("Sign out"))
{
MessageBox.Show("Login Successful");
}
}
#4
Re: How to automate a login into a jsp site to download a file
Posted 14 October 2010 - 12:26 PM
public static Response UploadImage(Image image)
{
...
using (WebClient wc = new WebClient())
{
var fields = GetFields(image);
try
{
var response = wc.UploadValues(someUrlPath, fields);
...
}
catch (Exception exc)
{
res.Exception = exc;
}
}
...
}
private static NameValueCollection GetFields(Image image)
{
NameValueCollection res = new NameValueCollection();
res.Add("key", someApiKey);
res.Add("image", image.ToBase64());
res.Add("type", "base64");
return res;
}
This will POST all values in the NameValueCollection to the provided URL.
Now, it may be that you have to maintain a state via a cookie or something like that. That will get more complicated.
This post has been edited by insertAlias: 14 October 2010 - 12:27 PM
#5
Re: How to automate a login into a jsp site to download a file
Posted 14 October 2010 - 12:28 PM
I will say that when you say "it doesn't work", that doesn't give us a lot to go on. Be specific as to what is not working.
#6
Re: How to automate a login into a jsp site to download a file
Posted 14 October 2010 - 12:32 PM
#7
Re: How to automate a login into a jsp site to download a file
Posted 14 October 2010 - 12:35 PM
InsertAlias, thanks for your post. I'll see what I can do with that.
This post has been edited by zwickz711: 14 October 2010 - 12:37 PM
#8
Re: How to automate a login into a jsp site to download a file
Posted 14 October 2010 - 12:43 PM
But that's strictly a wild-ass guess
#9
Re: How to automate a login into a jsp site to download a file
Posted 14 October 2010 - 01:18 PM
#10
Re: How to automate a login into a jsp site to download a file
Posted 18 October 2010 - 01:25 PM
#11
Re: How to automate a login into a jsp site to download a file
Posted 18 October 2010 - 02:26 PM
Just one forum that mentions this:
http://forums.devx.c...ad.php?t=147646
Anyway, I'd suggest against using the WebBrowser and use the WebClient object. It's different, you'll have to re-figure it out, but you can download a file without any dialog box using it.
Also, you could try using HttpWebRequest. That works as well. More manual work, but more fine control.
#12
Re: How to automate a login into a jsp site to download a file
Posted 19 October 2010 - 05:20 AM
insertAlias, on 18 October 2010 - 01:26 PM, said:
Just one forum that mentions this:
http://forums.devx.c...ad.php?t=147646
Anyway, I'd suggest against using the WebBrowser and use the WebClient object. It's different, you'll have to re-figure it out, but you can download a file without any dialog box using it.
Also, you could try using HttpWebRequest. That works as well. More manual work, but more fine control.
That's exactly what I had found too but wanted to make sure. I've considered using the others but I'm unsure of how to manipulate the html of the page in order to login to the page to access the file download url. Any ideas there?
This post has been edited by zwickz711: 19 October 2010 - 05:21 AM
#13
Re: How to automate a login into a jsp site to download a file
Posted 21 October 2010 - 12:00 PM
IE ie = new IE("urltologinto");
//ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide);
//html tags to find by name
ie.TextField(Find.ByName("USER")).TypeText("username");
ie.TextField(Find.ByName("Password")).TypeText("password");
ie.Button(Find.ByName("Login")).Click();
//file download handler to handler dialog box
FileDownloadHandler handler = new FileDownloadHandler(@"FileLocationHere");
ie.AddDialogHandler(handler);
ie.WaitForComplete();
ie.GoTo(@"urltodownload");
handler.WaitUntilFileDownloadDialogIsHandled(5);
handler.WaitUntilDownloadCompleted(20);
#14
Re: How to automate a login into a jsp site to download a file
Posted 14 March 2012 - 07:38 AM
zwickz711, on 21 October 2010 - 12:00 PM, said:
IE ie = new IE("urltologinto");
//ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide);
//html tags to find by name
ie.TextField(Find.ByName("USER")).TypeText("username");
ie.TextField(Find.ByName("Password")).TypeText("password");
ie.Button(Find.ByName("Login")).Click();
//file download handler to handler dialog box
FileDownloadHandler handler = new FileDownloadHandler(@"FileLocationHere");
ie.AddDialogHandler(handler);
ie.WaitForComplete();
ie.GoTo(@"urltodownload");
handler.WaitUntilFileDownloadDialogIsHandled(5);
handler.WaitUntilDownloadCompleted(20);
Would be able to show me how did you implemet this in your code, I need to do the exact same thing in a webapplication but I need to get an instance of IE Which is already running, please help I have been trying to do this forever
|
|

New Topic/Question
Reply
MultiQuote








|