简体   繁体   中英

Call a url from C# Windows Application

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM