Python 官方文档:入门教程 => 点击学习
#!/usr/bin/env python # -*- coding: utf-8 -*- import requests import JSON def call(body,url): headers = {} #
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import JSON
def call(body,url):
headers = {}
# 这里有个细节,如果body需要json形式的话,需要做处理
# 可以是data = json.dumps(body)
response = requests.post(url, data = json.dumps(body), headers = headers)
# 也可以直接将data字段换成json字段,2.4.3版本之后支持
# response = requests.post(url, json = body, headers = headers)
# 返回信息
print response.text
# 返回响应头
print response.status_code
return "回调发送成功"
if __name__=="__main__":
url = "Http://192.168.0.128:8080/api/reGISter/result"
data = '[{"bugid": "12260", "type": "success", "bugname": "firefox"}, {"bugid": "12261", "type": "success", "bugname": "xulrunner"}, {"bugid": "12262", "type": "failed", "bugname": "xulrunner-devel"}]'
call(data,url)
--结束END--
本文标题: python调用rest接口
本文链接: https://www.lsjlt.com/news/191998.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0