Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a url from C# Windows Application

Tags:

c#

windows

I have a url which sends sms to the provided mobile numbers. I want to just call this url from windows application but not to open in browser. I just want to execute that url from my windows application.

example of url

    http://mycompany.com/sms.aspx?mobilenum=9123444777&Message=this is a test message

I have tried in this way. But it is opening in a browser. I dont want this to be opened in a browser. I just want to execute this line internally.

    System.Diagnostics.ProcessStartInfo sInfo = new     
    System.Diagnostics.ProcessStartInfo("http://mycompany.com
    /sms.aspx?mobilenum=9123444777&Message=this is a test message");
    System.Diagnostics.Process.Start(sInfo);

Thanks.

like image 501
Shahid Aleem Avatar asked Feb 05 '26 05:02

Shahid Aleem


2 Answers

Have you tried to use a HttpWebRequest?

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://mycompany.com/sms.aspx?mobilenum=9123444777&Message=this%20is%20a%20test%20message");
WebResponse response = request.GetResponse();
response.Close(); 
like image 125
kjbartel Avatar answered Feb 06 '26 17:02

kjbartel


You can't "execute" url like that... URL is an address of a resource that you can use only by sending a request to the remote server. So instead you want to post data using a query string (make an HTTP request). You can achieve that for example by using WebClient class...

http://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.110%29.aspx

like image 39
walther Avatar answered Feb 06 '26 17:02

walther



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!