zoukankan      html  css  js  c++  java
  • 发送带json body的get请求

     

    用curl:

    curl -X GET "127.0.0.1:8001" -d "{'a':1,'b':2}"

    用python requests:

    import requests
    requests.get(url="127.0.0.1:8001", data={'a':1,'b':2})

    参考:https://juejin.im/entry/5badb020f265da0ac962abf2

    当我们被问及 HTTP 的 GET 与 POST 两种请求方式的区别的时候,很多答案是说 GET 的数据须通过 URL 以 Query Parameter 来传送 ,而 POST 可以通过请求体来发送数据,所以因 URL 的受限,往往 GET 无法发送太多的字符。

    GET 果真不能通过 Request Body 来传送数据吗?

    非也。

    如此想法多半是因循着网页中 form 的 method 属性只有 get 与 post 两种而来。

    因为把 form 的 method 设置为 post,表单数据会放在 body 中,而 method 为 get(默认值) 时,提交时浏览器会把表单中的字符拼接到 action 的 URL 后作为 query parameter 传送。

    GET vs POST

    于是乎就有了这么一种假像:HTTP GET 必须通过 URL 的查询参数来发送数据。

    其实 HTTP 规范并未规定说 GET 就不能发送 body 数据,在 RFC GET 中只是说:

    The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.

  • 相关阅读:
    DBC的故事
    MDF,了解一下
    PAT A 1059 Prime Factors (25分)
    素数的判断与素数表的获取
    PAT A 1014 Waiting in Line (30分)
    n皇后问题(全排列+回溯)
    最长回文子串(c++)
    传输方式的分类
    OSI模型概述
    进制转换
  • 原文地址:https://www.cnblogs.com/zealousness/p/12166591.html
Copyright © 2011-2022 走看看