Python简单模拟POST请求

1、

# -*- coding: utf-8 -*
import requests

url = "https://xxx/Account/Login"

querystring = {"LoginName":"xxx","PassWord":"xxx"}
headers = {}

response = requests.request("POST", url, headers=headers, params=querystring)

print(response.text)

2、

# -*- coding: utf-8 -*
import requests
import json

url = "https://xxx/Account/Login"
headers = {}
querystring = {"LoginName":"xxx","PassWord":"xxx"}
#send requests
response = requests.request("POST", url, headers=headers, params=querystring)
#转义成json
results=json.loads(response.text)
#print results
#print response.text
#获取状态码
print"状态码:",response.status_code
#print results['msg']
#检验结果
if(results['result']==1):
    print"结果:", results['msg']
else:
    print '登录失败'

PS:注意headers{}中的填写,如果不知道需要什么,可以使用Fildder模拟一下

你可能感兴趣的:(Python)