Reputation:
First of all i am doing a Windows application. Not a web application.
Now i am doing on application to send SMS (Short message) from System to Mobile.
Here, i am using a http URL to push the message having parameters To (number) and Msg (test message).
after forming the URL, like
Here i mentioned 3 for ip address, X for passwords and user id because of confidential.
After sending this URL, i am receiving some text like "Message Send Successfully", in the browser window.
Just i want to read the text and store in the database.
My problem is: how can i read the text from the web browser.
please held me!
Upvotes: 4
Views: 7446
Reputation: 86482
Using .NET , see WebClient Class - Provides common methods for sending data to and receiving data from a resource identified by a URI.
Seen here a few times, e.g. fastest c# code to download a web page
EDIT: the System.Net.WebClient
class is not connected to web applications, and can be easily used in console or winforms applications. The C# example in the MSDN link is a standalone console app (compile and run it to check):
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 ();
}
}
Upvotes: 2
Reputation: 95674
Here's a code from Microsoft's 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 ();
}
}
Upvotes: 0