HttpRequestsUtil.py 829 B

12345678910111213141516171819202122232425262728293031
  1. # coding=utf-8
  2. import requests
  3. import json
  4. class HttpRequestsUtil(object):
  5. #post方法获取数据 application/json
  6. @staticmethod
  7. def post(url, postData,headers): #
  8. data = json.dumps(postData)
  9. response = requests.request("POST",url, data=data.encode('utf-8'),
  10. headers=headers)
  11. res = response.json()
  12. return res
  13. @staticmethod
  14. def get(url,getData): #
  15. response = requests.request("GET",url+getData)
  16. res = response.json()
  17. # print(res)
  18. return res
  19. if __name__ == '__main__':
  20. httputil = HttpRequestsUtil()
  21. # httputil.postText()
  22. # HttpUtil.postText()
  23. # httputil.get("http://web.sagacloud.cn:8008/sgdaping/duoduo-service/setup-service/environment/queryConditionerStatus?projectId=","Pj1101010007")