# python post or get请求demo import requests; import json; headers={ "Content-Type":"application/json" } ##公共参数 data = {"公共参数1":"","公共参数2":"0","公共参数3":"11"} payNos = [ #["参数1","参数2","参数3","参数4","参数5","参数6","参数7","参数8"] ] for x in payNos: data['para1'] = x[0] data['para2'] = x[1] data['para3'] = x[2] data['para4'] = x[3] data['para5'] = x[4] data['para6'] = x[5] data['para7'] = x[6] data['para8'] = x[7] #POST请求 r = requests.post(url="http://IP:端口/url",data=json.dumps(data), headers=headers); #Get请求 #print(x + "--- start") #r = requests.get(url="http://IP:端口/url?orderNo=" + x); #print(x + "---" + r.text) file_name = 'log/log.txt' textJson = json.loads(r.text) print(textJson) with open(file_name, 'a') as file_obj: file_obj.write(data['para1'] + "-" + str(textJson) + "\n")
标签:get,python,demo,json,参数,file,post,data From: https://www.cnblogs.com/oktokeep/p/16588051.html