C #: how to read data from webbrowser in windows application

First of all, I am making a Windows application. Not a web application.

Now I am doing in the application to send SMS (short message) from System to Mobile.

Here I use an http address to enter a message with the parameters To (number) and Msg (test message).

after generating a url e.g.

http : //333.33.33.33ogi333/csms/PushURL.cgi ? USERNAME=xxxx&PASSWORD=xxxx&MOBILENO=919962391144&MESSAGE=TestMessage&TYPE=0&CONTENT_TYPE=text ;

Here I mentioned 3 for ip address, X for passwords and user id due to privacy.

After sending this URL, I get text in the browser window, for example, "Message Send Successfully".

I just want to read the text and save it in the database.

My problem: how can I read text from a web browser.

please hold me!

+4
source share
2 answers

Using .NET, see WebClient Class - Provides common methods for sending data and retrieving data from a resource identified by a URI.

It is visible here several times, for example. fast c # code to load web page

EDIT : the System.Net.WebClient class is not connected to web applications and can be easily used in console or winform applications. The C # example in the MSDN link is a standalone console application (compile and run it for verification):

 using System; using System.Net; using System.IO; public class Test { public static void Main (string[] args) { if (args == null || args.Length == 0) { throw new ApplicationException ("Specify the URI of the resource to retrieve."); } WebClient client = new WebClient (); client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); Stream data = client.OpenRead (args[0]); StreamReader reader = new StreamReader (data); string s = reader.ReadToEnd (); Console.WriteLine (s); data.Close (); reader.Close (); } 

}

+2
source

Here is the code from the Microsoft WebClient Class .

 using System; using System.Net; using System.IO; public class Test { public static void Main (string[] args) { if (args == null || args.Length == 0) { throw new ApplicationException ("Specify the URI of the resource to retrieve."); } WebClient client = new WebClient (); // Add a user agent header in case the // requested URI contains a query. client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); Stream data = client.OpenRead (args[0]); StreamReader reader = new StreamReader (data); string s = reader.ReadToEnd (); Console.WriteLine (s); data.Close (); reader.Close (); } } 
0
source

All Articles