asp.net 2.0 Ajax

Source: Internet
Author: User
Tags http post

When a Web service is invoked asynchronously using the ASP.net Ajax asynchronous communication layer, the HTTP POST method is applied by default. But in order to provide sufficient flexibility, the ASP.net Ajax asynchronous communication layer also allows us to invoke using HTTP GET.

When invoked using an HTTP GET, the parameters of the method are serialized into a JSON string, which is then coded and added to the URL to be sent back to the server for processing. The comparison of Get and default post methods has been described in detail in chapter 2nd and is not repeated here.

If you want to call a method in a Web service in the form of an HTTP GET, add the [Scriptmethod = True] property to the method. For example, for example programs in section 3.1, we can modify the definition of the method in the server-side Web service as follows, and note the bold part:

[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public string SayHelloUsingGET(string name)
{
  return string.Format("Hello {0}!", name);
}

Run the sample program again and open the HTTP sniffer to see that this asynchronous call does use HTTP GET. As shown in Figure 3-9.

When using HTTP GET requests for Web service, pay special attention to security issues. In general, you can use HTTP GET only if you are not exposed to sensitive information and do not have critical operations such as deleting/updating data.

Figure 3-9 Invoking the Web service using HTTP GET

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.