request实例1:

import requests
payload = {'key1':'value','key2':'value2'}
url = "http://httpbin.org/get"
headers = {'content-type': 'application/json'}
res = requests.get(url,params=payload,headers=headers)
res.encoding="utf-8"
print("1.url: ")
print(res.url)
print("2.text: ")
print(res.text)
print("3.json: ")
print(res.json())
print("4.status_code: ")
print(res.status_code)

结果:

1.url:
http://httpbin.org/get?key1=value&key2=value2
2.text:
{
"args": {
"key1": "value",
"key2": "value2"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"origin": "117.25.182.2",
"url": "http://httpbin.org/get?key1=value&key2=value2"
} 3.json:
{'args': {'key1': 'value', 'key2': 'value2'}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'origin': '117.25.182.2', 'url': 'http://httpbin.org/get?key1=value&key2=value2'}
4.status_code:
200

request实例2:

import requests
payload = {'key1':'value1','key2':'value2'}
url = "http://httpbin.org/post"
headers = {'content-type': 'application/json'}
res =requests.post(url,data=payload,headers=headers)
print("1.url: ")
print(res.url)
print("2.text: ")
print(res.text)
print("3.json: ")
print(res.json())
print("4.status_code: ")
print(res.status_code)

  结果:

1.url:
http://httpbin.org/post
2.text:
{
"args": {},
"data": "key1=value1&key2=value2",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "23",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"json": null,
"origin": "117.25.182.2",
"url": "http://httpbin.org/post"
} 3.json:
{'args': {}, 'data': 'key1=value1&key2=value2', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Length': '23', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'json': None, 'origin': '117.25.182.2', 'url': 'http://httpbin.org/post'}
4.status_code:
200

 request实例3: 

import requests
url = 'http://httpbin.org/cookies'
cookies = dict(cookies_are='working')
r = requests.get(url, cookies=cookies)
print("1.url: ")
print(res.url)
print("2.text: ")
print(res.text)
print("3.json: ")
print(res.json())
print("4.status_code: ")
print(res.status_code)

  

结果:

1.url:
http://httpbin.org/post
2.text:
{
"args": {},
"data": "key1=value1&key2=value2",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "23",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.18.4"
},
"json": null,
"origin": "117.25.182.2",
"url": "http://httpbin.org/post"
} 3.json:
{'args': {}, 'data': 'key1=value1&key2=value2', 'files': {}, 'form': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Content-Length': '23', 'Content-Type': 'application/json', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'json': None, 'origin': '117.25.182.2', 'url': 'http://httpbin.org/post'}
4.status_code:
200

  

最新文章

  1. Mysql忽略文件名的安全编码
  2. POJ 2828 线段树(想法)
  3. 【C++沉思录】代理类
  4. 协作图 Collaboration diagram
  5. UC 浏览器远程调试手机web网页记录
  6. jquery 源码剖析1
  7. 关于playmaker play animation出现警告 The AnimationClip 'xxx' used by the Animati ...
  8. 自定义弧形的 tabBar
  9. hdu 4400 Mines(离散化+bfs+枚举)
  10. js设置奇偶行数样式
  11. 一个web应用的诞生--美化一下
  12. 19.最省钱的app发短信方法
  13. 查询APP Store已发布过的版本记录
  14. 学JAVA第十七天,接口与抽象方法
  15. FFmpeg部署及相关指令操作说明
  16. LoadRunner(一)——性能测试基础及性能指标概述
  17. SpringBoot整合模板引擎
  18. codeforces492C
  19. html页面背景设定相关
  20. Node学习笔记2:建立HTTP服务器和客户端之间的通信

热门文章

  1. 安装scrapy解决的坑
  2. advance shading--光源的类型
  3. MySQL中触发器
  4. UVa 1025 A Spy in the Metro (DP动态规划)
  5. jmeditor与CKEditor4x整合的BUG
  6. Java之RandomAccessFile小结
  7. Jmeter-Ant 生成测试报告
  8. [SAP]编辑表
  9. Android-Sqlite-升级操作
  10. long polling