473,516 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading PostData from WebBrowser

116 New Member
Hi

I have a WebBrowser on a form. On loading, the browser finds an online login page.

After logging in via this page some postdata is generated, say forename and surname.

There should be a way to read this via BeforeNavigate2 but nothing seems to work. I've tried using WebBrowser and AxWebBrowser but can't find any code that reads the data. Outputting the URL doesn't help as the post data isn't part of the URL.

Apparently BeforeNavigate2 only works on AxWebBrowser in 2010 which only increases the confusion.

Anyone have any simple known working code that can grab the post data from an embedded browser in vb2010?

Many thanks
Jul 1 '14 #1
4 4189
Luk3r
300 Contributor
I actually used code from here http://stackoverflow.com/questions/1...in-vb-net-2010 and it seemed to work fine. I've included the code I used for a quick copy & paste so you can see if it suits your needs.

All I did in advance was set my WebBrowser1 URL in the properties window and added a multi-line textbox to see the output.

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Net
  3. Imports System.Windows.Forms
  4.  
  5.  
  6. Public Class Form1
  7.     Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
  8.         Dim req As WebRequest
  9.         Dim res As WebResponse
  10.         Dim postDataStream As Stream
  11.         Dim webResponse As String = ""
  12.  
  13.         Try
  14.             req = WebRequest.Create(e.Url.ToString)
  15.             req.Method = "POST"
  16.             res = req.GetResponse
  17.             postDataStream = res.GetResponseStream
  18.             Dim webStreamReader As New StreamReader(postDataStream)
  19.             While webStreamReader.Peek >= 0
  20.                 webResponse = webStreamReader.ReadToEnd
  21.             End While
  22.             TextBox1.Text = webResponse.ToString
  23.         Catch ex As Exception
  24.             'do something for exceptions
  25.         End Try
  26.     End Sub
  27. End Class
Jul 1 '14 #2
robertybob
116 New Member
Thx Luk3r,

I think I actually had a try with this but it seemed to output the code for the page rather than just the post data.

However I'll have a look tomorrow to see if that was a mistake on my part.

Just to clarify, if the online login page response posts ?forename=Bill&surname=Smith that's all I need to read.

Will see how it goes and will let you know once I've had time to have a look.

Many thanks
Jul 1 '14 #3
robertybob
116 New Member
I can confirm that this method grabs the page source rather than just postdata unfortunately.
Jul 2 '14 #4
robertybob
116 New Member
Ok I finally found something that works - but only because I know the name of the element I require. Not sure how to do this without that knowledge but for my purposes the following works.

Expand|Select|Wrap|Line Numbers
  1. Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
  2.         Dim thiselm As HtmlElement
  3.         thiselm = WebBrowser1.Document.GetElementById("surname")
  4.         If Not thiselm = Nothing Then TextBox1.Text = Uri.EscapeUriString(thiselm.GetAttribute("value").ToString)
  5.     End Sub
  6.  
Jul 2 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
4892
by: Koonaka | last post by:
Hi all, I am tryiing to post data from one web page to another using the webbrowser control's navigate2 or navigate method. The examples I can find tell me that i need to send the post data in ascii binary format which can be done in a safearray. Does anyone know how to do this in VB6 or is there another way? Thanks
0
1671
by: mic | last post by:
I'm stuck with following problem. Using webbrowser control I try to make custom-made request. I found working example of this written in VBS but porting it to Python doesn't seem to work. The key is navigate (or navigate2) method, that accepts PostData as one of it's parameters. As stated in reference: "The post data specified by PostData is...
0
1356
by: Mike Schellhase | last post by:
I am building a Windows application that hosts an ASP.NET application using the MS Web Browser Control. (see http://www.west-wind.com/presentations/aspnetruntime/aspnetruntime.asp for a similar app). I run into problems if one of my ASP.NET pages needs to upload a file (via HTTP). I am using the BeforeNavigate2 event of the Web Browser Control...
0
1851
by: Sharon | last post by:
Hi all. I'm using the WebBrowser class and sometimes i get this exception: System.Windows.Forms.IWebBrowser2.Navigate2(Object& URL, Object& flags, Object& targetFrameName, Object& postData, Object& headers) +0 System.Windows.Forms.WebBrowser.PerformNavigate2(Object& URL, Object& flags, Object& targetFrameName, Object& postData, Object&...
6
11241
by: ESmith | last post by:
I'm looking to user a web browser component in VS2005. I like the functionality in the AXWebBrowser component (from ActiveX controls page) that allows me to do this: mshtml.HTMLDocument doc; doc = (mshtml.HTMLDocument)this.SecureWebBrowser.Document; mshtml.HTMLButtonElement ButtonTest =
1
3285
by: L. Chernov | last post by:
Hello, I am trying to work with .Net 2005 WebBrowser object, and put it on a "Windows control library" (embedded in a user control class) and then I am executing it from an ASP.Net webform(with IE6) with the following object tag: <OBJECT id="ModPkiObj" height="550" width="800"...
0
5522
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
14
2073
by: Ron Adam | last post by:
Is anyone else having problems with the webbrowser module? Python 2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25) on linux2 Type "help", "copyright", "credits" or "license" for more information. True It opens firefox as expected, but the url is ...
4
4179
by: dennijr | last post by:
sry its long, questions in the last sentance if u wanna jump to it. i just decided that i would include everything that led up to the problem i made a gif video that i wanted to put into a program, and i couldnt figure out how to get it into VB6. finally i found out that the Microsoft Internet Control would play the gif file if i...
0
1469
by: Ekart Laszlo | last post by:
Hi, there We have currently a Java Applet based solution that we would like to rewrite to a .NET solution. The scenario is the following: 1. Starter Client application opens up a web browser window and makes a HTTP request with a big raw postdata to a remote server. 2. In this web browser window a Java Applet based application shall...
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.