zoukankan      html  css  js  c++  java
  • 浏览器和服务器之间数据读取

    浏览器发送的数据格式:

    get: 是从url栏发送    例如:/index/?a=1&b=2

    get方式没有请求体    request.body 是一个空的  b''

    post: 通过form表单发送    默认发送的数据类型是urlencoded

    只有post才有请求体

    <form action="" method="post">
            {%csrf_token%}
            <input type="text" name="abc">
            <input type="submit">  或者 用button按钮
    </form>

    form表单是以name为键, 以用户输入的内容为值, 以键值对的形式发给服务器的

    服务器接收的数据格式:

    get请求: 

    request.GET: <QueryDict: {'a': ['1'], 'b': ['2']}>
    
    request.body: b
    ''

    post请求:

    request.POST: 
    <QueryDict: {'csrfmiddlewaretoken': ['Cq3vrx44y1NGgAgUupJ1eBP4NBbGaLWwq5Cx43acmB4AYRIiqYh2LB0wsGJTjJwq'], 'abc': ['222222222']}>
    
    request.body: b
    'csrfmiddlewaretoken=Cq3vrx44y1NGgAgUupJ1eBP4NBbGaLWwq5Cx43acmB4AYRIiqYh2LB0wsGJTjJwq&abc=222222222'

    从服务器中取数据:

    get 形式:  

    服务器接收到的数据 <QueryDict: {'a': ['1'], 'b': ['2']}>

    recv= request.GET.get(“a”)  #get取数据
    print(recv)     #1

    post形式: 

    服务器接收的数据形式:

    <QueryDict: {'csrfmiddlewaretoken': ['rXl2iAESA6Cju8y24Zc4oz3hDUIkwqnbfCU4V6K0oGTdcp0q0yK5VzeJiZgxFoX5'], 
    'abc': ['111111111111111']}>
    print(request.POST.get("abc"))  #post取数据
  • 相关阅读:
    spring_three
    报错:java.sql.SQLException: The server
    Spring_two
    Spring_One
    Mybatis中的collection和association一关系
    Mybatis_three
    文件操作1
    面向对象编程三大特征7
    面向对象编程三大特征6
    面向对象编程三大特征5
  • 原文地址:https://www.cnblogs.com/kenD/p/10066527.html
Copyright © 2011-2022 走看看