前端 get、post发送数据报文怎么封装

  1. get
  1. post
# 1
https://restapi.amap.com/v3/geocode/geo?address=北京市朝阳区阜通东大街6号&output=XML&key=<用户的key>
https://lbs.amap.com/api/webservice/guide/api/georegeo/

# 2
#对应方法
def gaode(addr):
    para = {
        'key':'你的',
        'address':addr
        }
    url = 'https://restapi.amap.com/v3/geocode/geo?'
    req = requests.get(url,para,timeout=5)
    req = req.json()
    print('-' * 30)
    if req['status']=='1':
        if len(req['geocodes']) > 0:
            m = req['geocodes'][0]['location']
            print(m)
        else:
            print("None")
            m = ""
    else:
        print("None")
    return m

```![](https://img2020.cnblogs.com/blog/2088892/202102/2088892-20210213085605829-51974060.png)
![](https://img2020.cnblogs.com/blog/2088892/202102/2088892-20210213091050173-1423028119.png)
![](https://img2020.cnblogs.com/blog/2088892/202102/2088892-20210213091102347-52574837.png)
posted @ 2020-07-08 11:30  该显示昵称已被使用了  阅读(525)  评论(0编辑  收藏  举报