# _*_ encoding:utf-8 _*_ import json import requests #post請求 payload = {"cindy":"hello world", "python":"1078370383"} r = requests.post('http://httpbin.org/post',data=payload) print (r.text) #輸出結果,data數據傳輸到form裏面 # { # "args": {}, # "data": "", # "files": {}, # "form": { # "cindy": "hello world", # "python": "1078370383" # }, # "headers": { # "Accept": "*/*", # "Accept-Encoding": "gzip, deflate", # "Connection": "close", # "Content-Length": "35", # "Content-Type": "application/x-www-form-urlencoded", # "Host": "httpbin.org", # "User-Agent": "python-requests/2.18.4" # }, # "json": null, # "origin": "211.140.31.50", # "url": "http://httpbin.org/post" # } #把payload轉換爲json格式,post的body是json類型 data_json = json.dumps(payload) r1 = requests.post('http://httpbin.org/post',data=data_json) print (r1.text) #輸出結果,返回結果傳回到data裏 # { # "args": {}, # "data": "{\"python\": \"1078370383\", \"cindy\": \"hello world\"}", # "files": {}, # "form": {}, # "headers": { # "Accept": "*/*", # "Accept-Encoding": "gzip, deflate", # "Connection": "close", # "Content-Length": "48", # "Host": "httpbin.org", # "User-Agent": "python-requests/2.18.4" # }, # "json": { # "cindy": "hello world", # "python": "1078370383" # }, # "origin": "211.140.31.50", # "url": "http://httpbin.org/post" # }