How to consume web method using http post?

How to access a web method using form post

I fail to access the method with the following code and get "Internet server error".

                System.Net.WebClient wc = new System.Net.WebClient();
                System.Collections.Specialized.NameValueCollection myNameValueCollection = new System.Collections.Specialized.NameValueCollection();
                myNameValueCollection.Add("Subject", "mySubject");
                myNameValueCollection.Add("Message", "myMessage");             
                byte[] bBack = wc.UploadValues(@"http://localhost:3663/mySite1/WebServices/Toolbox.asmx/SendEmailByWebService", "POST", myNameValueCollection);

The web method SendEmailByWebService simply send a email using parameters Subject and Message.

I get the following error:

{System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
   at System.Net.WebClient.UploadValues(String address, String method, NameValueCollection data)
  

What is wrong with the code

Thanks a lot.

 




Answer this question

How to consume web method using http post?

  • How to consume web method using http post?