tags:

views:

1682

answers:

2

Hi friends,

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

http://333.33.33.33:3333/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 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!

A: 

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 ();
 }
}
eed3si9n
No need for all that stream nonsense, just use client.DownloadString
John Sheehan
thanks gimel, i forgot to say one thing , i am developing a windows application, not a web application
thanks eed3si9nplese guide me for Windows appliciation.
thanks eed3si9n...its working.... its correct.
+2  A: 

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 ();
}

}

gimel
thanks gimel, i forgot to say one thing , i am developing a windows application, not a web application
No problem, WebClient is not related to web apps (see edit).
gimel