Now we will modify the application that we developed in the previous post to work with POST parameter
We have changed the get to post as we are now not passing the value for Name by appending it in the url.
Only make changes to the function getMessage()
xmlHttp.open(“POST“, “http://localhost/WebService1/Service1.asmx/HelloWorld”, true);
Let’s understand the changes that we have made
First of all we have change the method of passing data to POST from GET.
But still we need to pass the name’s value which our web service method needs.
For that we’ll modify our Send() method
We are using the same name/value pair in send() which we used at the end of the request URL in the GET version
escape()-It makes sure that the values are valid values i.e. no tricky characters are there.
But this is not enough that is why we added this line
Here the server doesn’t know what kind of data it can expect or is coming from our application.
We are making use of setRequestHeader function to tell the server about the content type we are going to send.
The server can get this information from request’s header that it recieves.
Content-Type -> Name of the header
application/x-www-form-urlencoded -> http://www.w3.org/TR/html4/interact/forms.html#h-184.108.40.206