zoukankan      html  css  js  c++  java
  • Ajax的get和post两种请求方式区别

    Ajax的get和post两种请求方式区别

    (摘录):http://ip-10000.blog.sohu.com/114437748.html

    解get和post的区别.

    1、 get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。post是通过HTTP post机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。

    2、 对于get方式,服务器端用Request.QueryString获取变量的值,对于post方式,服务器端用Request.Form获取提交的数据。两种方式的参数都可以用Request来获得。

    3、get传送的数据量较小,不能大于2KB。post传送的数据量较大,一般被默认为不受限制。但理论上,因服务器的不同而异.

    4、get安全性非常低,post安全性较高。

    5、 <form method="get" action="a.asp?b=b">跟<form method="get" action="a.asp">是一样的,也就是说,method为get时action页面后边带的参数列表会被忽视;而<form method="post" action="a.asp?b=b">跟<form method="post" action="a.asp">是不一样的。

    数据是 username=张三 :
    GET 方式, 浏览器键入 http://localhost?username=张三


    GET /?username=%E5%BC%A0%E4%B8%89 HTTP/1.1
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
    Accept-Language: zh-cn
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
    Host: localhost
    Connection: Keep-Alive

    POST 方式:

    POST / HTTP/1.1
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
    Accept-Language: zh-cn
    Content-Type: application/x-www-form-urlencoded
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
    Host: localhost
    Content-Length: 28
    Connection: Keep-Alive

    username=%E5%BC%A0%E4%B8%89


    比较一下上面的两段文字, GET 方式把表单内容放在前面的请求头中, 而 POST 则把这些内容放在请求的主体中了, 同时 POST 中把请求的 Content-Type 头设置为 application/x-www-form-urlencoded.

    注: encodeURIComponent 返回一个包含了 charstring 内容的新的 String 对象(Unicode 格式), 所有空格、标点、重音符号以及其他非 ASCII 字符都用 %xx 编码代替,其中 xx 等于表示该字符的十六进制数。 例如,空格返回的是 "%20" 。 字符的值大于 255 的用 %uxxxx 格式存储。参见 JavaScript 的 encodeURIComponent() 方法.

    在了解了上面的内容后我们现在用ajax的XMLHttpRequest对象向服务器分别用GET和POST方式发送一些数据。

    GET 方式
    var postContent ="name=" + encodeURIComponent("xiaocheng") + "&email=" + encodeURIComponent("xiaochengf_21@yahoo.com.cn");
    xmlhttp.open("GET", "somepage" + "?" + postContent, true);
    xmlhttp.send(null);


    POST 方式

    var postContent ="name=" + encodeURIComponent("xiaocheng") + "&email=" + encodeURIComponent("xiaochengf_21@yahoo.com.cn");
    xmlhttp.open("POST", "somepage", true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //xmlhttp.setRequestHeader("Content-Type", "text/xml"); //如果发送的是一个xml文件
    xmlhttp.send(postContent);

  • 相关阅读:
    Unity AnimatorController注意事项
    OpenGL ES入门详解
    手游性能优化之深入理解Texture Compression
    Unity2016 Unity3D开发VR游戏的经验
    U3D手游《苍穹变》性能优化经验谈
    unity5之代码创建状态机,玩的666
    Unity IK(反向运动学)初探
    根运动 (Root Motion) – 工作原理
    一些传感器相关的文章
    陀螺仪与加速传感器数据的融合算法解析
  • 原文地址:https://www.cnblogs.com/wangcq/p/3482548.html
Copyright © 2011-2022 走看看