James, Thank you for your answer. This could do the trick. I'll try it out. I already was thinking about changing the HttpWebRequest in another method, because in my opinion a WebRequest is the equivalent of a GET. What I need is a POST, so I'm thinking of using an HttpWebResponse...
Dimitri Backaert
Posts
-
[C#.NET 2008] Screen-scraping a HTML Page -
[C#.NET 2008] Screen-scraping a HTML PageThis might all seem very funny, I know, but it doesn't solve my problem.... :doh: Concerning the chairman, A request has been sent by my manager. But this might take a while to achieve (office / political war between Belgium / Netherlands). The main reason why the Netherlands are unwilling to release information, is that they were formerly the only group that maintained all the ICT infrastructure for the whole Benelux company group. However, since the beginning of 2009, Belgium and Luxemburg splitted from the Netherlands, and created their own ICT division. I think it's some sort of Job Protection... Politics, money, it's all involved. And it's - excuse my language - a real pain in the ass...
-
[C#.NET 2008] Screen-scraping a HTML PageYes I do, it's to prevent unauthorised access to the page... :laugh: However, this is a Web page that exists on the intranet of our company network. It displays certain measures which we want to display on a Dashboard application. The idea is to have an overview of these values at the blink of an eye (the dashboard will be projected on a whiteboard). Normally, we would use a read account on the database for this, but (since the database is being managed by the Netherlands and I am a Belgian employee) the Netherlands are refusing to give us a read account. So this is the only way how we can succeed in building the dashboard.
-
[C#.NET 2008] Screen-scraping a HTML PageHi, I'm trying to process the HTML source code from a certain web page. This web page has security enabled, using a Username & a password. I'm using the following method to try to access the page:
public static string GetHtmlPageSource(string url, string username, string password)
{WebClient wc = new WebClient(); wc.Credentials = new NetworkCredential(username, password); try { using (Stream stream = wc.OpenRead(new Uri(url))) { using (StreamReader reader = new StreamReader(stream)) { return reader.ReadToEnd(); } } } catch (WebException e) { //Error handeling return e.ToString(); }
}
This doesn't work however, I seem to be stuck at the logon page. I'm not able to pass the user security. Anyone has an idea?
-
Getting HTML Source from a WebPage in String-format, using NetworkCredentials [modified]Nobody? :-S This is what I found out: - The "page" variable gets a value, but when viewing this value using the built-in HTML viewer, I get the login-page. - At the bottom of this page, a message is displayed saying "Your browser is not supported". Could this cause the problem? If so, is there an alternative to make this work? Thanks in advance.
-
Getting HTML Source from a WebPage in String-format, using NetworkCredentials [modified]Hi, In order to create a dashboard application, I need to read an HTML site's source code. This contains the values (integers) which I want to process. I don't have access to the SQL-database, so this is the only way I can achieve my goal, and deliver the application. The site uses a Username & Password as security, and I am able to access the login page. However, when passing the credentials, I'm not able to read the source code (it seems like the credentials aren't valid). However, when using the same credentials directly in Internet Explorer, I'm able to access the webpage. This is the code I have so far. Any of you experts see what I'm doing wrong? PS: I've changed the site-url, username & password, since it's a confidential site of my company.
public static string GetHtmlPageSource(string url, string username, string password) { System.IO.Stream st = null; System.IO.StreamReader sr = null; try { // make a Web request System.Net.WebRequest req = System.Net.WebRequest.Create(url); // if the username/password are specified, use these credentials if (username != null && password != null) req.Credentials = new System.Net.NetworkCredential(username, password); // get the response and read from the result stream System.Net.WebResponse resp = req.GetResponse(); st = resp.GetResponseStream(); sr = new System.IO.StreamReader(st); // read all the text in it return sr.ReadToEnd(); } catch (Exception ex) { return string.Empty; } finally { // always close readers and streams sr.Close(); st.Close(); } } private void DataRefresh\_Tick(object sender, EventArgs e) { // Set the Refresh Interval to 15000 ms this.DataRefresh.Interval = 15000; // Declare the Variables, needed for this Application string FL, SL, UnFL, UnSL, ValueFL, ValueSL, ValueUnFL, ValueUnSL; //// Refresh the TopDesk Web Browser Object this.TopDesk.Refresh(); //Read WebPage string page; page = GetHtmlPageSource("https://site", "user", "pass"); //
-
VB.NET 2008: Hide and/or disable Start Menu onLoadIsn't there another way around? Like, an auto closing MessageBox, displaying for example the text "Please wait. Your information is being printed", and when closing the MessageBox, returning to the startup page (which is also defined as TopMost)?
-
VB.NET 2008: Hide and/or disable Start Menu onLoadHi, I have a Windows Form application that runs TopMost. In this application, there is a print function, which silently prints out a PDF file to the default printer. At the load of the Form, since the TopMost property is set to True, the Start Menu is hidden, which is exactly what I want. However, when the printing action is launched, the Start Menu pops up. This is triggered by the Taskbar (a little print icon is shown upon printing). Is there a way to prevent this? This application needs to run at an exposition, and will be launched on a touchscreen computer. The idea behind this, is that a customer can print a brochure of a product he's interested in. Secondly, I want to disable all the default shortcut keys to close the application (like ALT + F4, CTRL + ALT + DEL, etc.). Any ideas anyone? Kindly yours
-
VB.NET: Error adding multiple rows in a DataGridView (not bound to a DataTable)Hi Liqz, Thanks! That did the trick. I'll keep in mind that next time, I'll include the error message. Cheers.
-
VB.NET: Error adding multiple rows in a DataGridView (not bound to a DataTable)Hi, I'm having problems adding multiple rows to a DataGridView, on the Load-event of a Windows Application Form. Adding one record doesn't cause a problem, but when adding the second record (using the identical code), an Exception is thrown. Here's my code so far (VB.NET 2008):
Private Sub BWMFPForm\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim dgvRow As New DataGridViewRow Dim dgvCell As DataGridViewCell Dim dgvButton As DataGridViewImageColumn Dim column As DataGridViewColumn 'Disable sorting for all Columns For Each column In DataGridViewBrochures.Columns column.SortMode = DataGridViewColumnSortMode.NotSortable Next 'Add Record 'Column 1: Machine dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = "Aficio MP 4000 / Aficio MP 5000" dgvRow.Cells.Add(dgvCell) 'Column 2: Speed dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = "40 PPM / 50 PPM" dgvRow.Cells.Add(dgvCell) 'Column 3: Language dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = "Nederlands" dgvRow.Cells.Add(dgvCell) 'Column 4: Image Print dgvButton = New DataGridViewImageColumn dgvButton.Image = Drawing.Image.FromFile("D:\\DEVPROJECTS\\MarketingTouchScreen\\TouchScreen\\images\\Print\_Icon.jpg") dgvButton.ReadOnly = True dgvButton.ImageLayout = DataGridViewImageCellLayout.Normal DataGridViewBrochures.Columns.Add(dgvButton) 'Add the Row DataGridViewBrochures.Rows.Add(dgvRow) 'Add Record 'Column 1: Machine dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = "Aficio MP 4000 / Aficio MP 5000" dgvRow.Cells.Add(dgvCell) 'Column 2: Speed dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = "40 PPM / 50 PPM" dgvRow.Cells.Add(dgvCell) 'Column 3: Language dgvCell = New DataGridViewTextBoxCell() dgvCell.Value = "Nederlands" dgvRow.Cells.Add(dgvCell) 'Column 4: Image Print dgvButton = New DataGridViewImageColumn dgvButton.Image = Drawing.Image.FromFile("D:\\DEVPROJECTS\\MarketingTouchScreen\\TouchScreen\\images\\Print\_Icon.jpg") dgvButton.ReadOnly = True dgvButton.ImageLayout = DataGridViewImageCellLayout.Normal DataGridViewBrochures.Columns.Add(dgvButton)