python call web api

  • 2532
  • 0

python call web api

https://stackoverflow.com/questions/13941742/rest-post-using-python-request 

import requests
import json
data = {"data" : "24.3"}
data_json = json.dumps(data)
headers = {'Content-type': 'application/json'}

response = requests.post(url, data=data_json, headers=headers)

https://jzchangmark.wordpress.com/2016/06/12/%E9%80%8F%E9%81%8E-curl%E3%80%81python%E3%80%81postman-%E4%BE%86-request-api/ 

import requests
import json

payload = {'bookname':'Mark','publisher':'xyz'}
response = requests.get("http://localhost:60443/api/values", params=payload)
response_dic = response.json()
print(response_dic)