vue 请求数据参数_请求:参数和数据之间的区别

vue 请求数据参数

This question pops up a lot on Stack Overflow, on GitHub, and in the IRC channel, so I thought I’d write a short post to address it. The question is, broadly, this:

这个问题在Stack Overflow,GitHub和IRC频道中经常出现,所以我想写一篇简短的文章来解决这个问题。 广义上讲,问题是:

How do I send data on a POST? I tried params, but that didn’t work!

如何在POST上发送数据? 我尝试了params ,但是那params

The answer is that Requests has two different arguments for ‘sending’ data on a HTTP request: params and data. Each one does something different, but in their simplest form they both accept a dictionary of keys and values.

答案是请求对于HTTP请求上的“发送”数据有两个不同的参数: paramsdata 。 每个人都做不同的事情,但它们都以最简单的形式接受键和值的字典。

params is all about the query string, and so is primarily used on GET requests. To see it in action, take a look at this chunk of code:

params全部与查询字符串有关,因此主要用于GET请求。 要查看它的实际效果,请看以下这段代码:

>>> params = {'hi': 'there', 'what': 'ho'}
>>> r = requests.get('http://httpbin.org/get', params=params)
>>> print r.request.url
http://httpbin.org/get?hi=there&what=ho>>> params = {'hi': 'there', 'what': 'ho'}
>>> r = requests.get('http://httpbin.org/get', params=params)
>>> print r.request.url
http://httpbin.org/get?hi=there&what=ho 

The key take away here is that the data that was passed to params ended up in the URL query string. This is what it’s for. Any string data passed in there will be correctly escaped and encoded, then added to the URL.

这里最重要的是,传递给params的数据最终出现在URL查询字符串中。 这就是它的目的。 在那里传递的任何字符串数据都将被正确地转义和编码,然后添加到URL中。

data works differently: it’s all about the request body. Again:

data工作方式有所不同:都是关于请求正文的。 再次:

翻译自: https://www.pybloggers.com/2013/07/requests-the-difference-between-params-and-data/

vue 请求数据参数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值