Python中的简单URL GET / POST函数

TIMEX:

我似乎无法在Google上找到它,但是我想要一个执行此操作的函数:

接受3个参数(或更多参数):

  • 网址
  • 参数字典
  • 发布或获取

返回结果和响应代码。

有一个摘要吗?

杂货店:

要求

https://github.com/kennethreitz/requests/

以下是一些常见的使用方式:

import requests
url = 'https://...'
payload = {'key1': 'value1', 'key2': 'value2'}

# GET
r = requests.get(url)

# GET with params in URL
r = requests.get(url, params=payload)

# POST with form-encoded data
r = requests.post(url, data=payload)

# POST with JSON 
import json
r = requests.post(url, data=json.dumps(payload))

# Response, status etc
r.text
r.status_code

httplib2

https://github.com/jcgregorio/httplib2

>>> from httplib2 import Http
>>> from urllib import urlencode
>>> h = Http()
>>> data = dict(name="Joe", comment="A test comment")
>>> resp, content = h.request("http://bitworking.org/news/223/Meet-Ares", "POST", urlencode(data))
>>> resp
{'status': '200', 'transfer-encoding': 'chunked', 'vary': 'Accept-Encoding,User-Agent',
 'server': 'Apache', 'connection': 'close', 'date': 'Tue, 31 Jul 2007 15:29:52 GMT', 
 'content-type': 'text/html'}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

以POST格式提交后,URL中的GET元素丢失

如何将标头设置为$ .get()或$ .post()函数

Python(Flask)中的Get和Post方法

简单的Python服务器使用JSON处理GET和POST请求

Express JS中的POST函数

python的SimpleHTTPServer do_GET和do_POST函数如何工作?

WordPress:如何挂钩get_the_post_thumbnail_url()函数

如何找出在同一函数处理程序中调用了哪些get和post请求?

python中的日志函数的简单绘图

WordPress函数get_post_gallery()不注册帖子的画廊

如何在request.POST.get()函数中使用串联?(Django / Python的)

PHP在WHERE函数中使用Get Post

Node.js中的GET / POST函数

get_post_gallery函数显示url onky不显示标题

会话验证中的GET与POST

PHP中的POST / GET

$ .post在ajaxstop函数中连续循环

将所有参数$ _POST或$ _GET输入到函数中,使用记事本++中的替换字符串

使用angular 2在同一函数中同时调用GET和POST服务调用

如果可以在php中的类内使用filter_input(POST或GET)函数

不能使用get_post(),get_post_meta()和其他函数

POST 函数不适用于我的 php 代码,但是在同一个函数中 GET 正在工作

Azure 函数 REST API 处理 GET POST

Python27 将方法传递给调用用户输入定义的适当 get|post|delete 的函数

Django 视图函数中的 POST 与 GET 方法

NodeJS http get方法访问url在响应函数中

REST 中的 GET 与 POST

如何在 Wordpress 中更改 _get_last_post_time 函数的日期格式

在 POST 函数中调用 GET 变量