活了二十几年,从来没有人给过我一次意外感动或惊喜,也没有人在我生日的时候给过我特别的礼物,生病的时候得到的只是一些不在身边的语言安慰,也不见谁真正的照顾过自己,甚至有的时候自己蒙头睡一觉就好了,也有人喜欢过我,但是从没见谁坚持过。
import json
import sys
import requests
import urllib
import time
# Login to serverurl
# Raises an exception if things don't work.
def login( auth_url, username, password ):
headers = {'Content-Type': 'application/json' }
login_values = {"username":username, "password":password}
r = requests.post( auth_url, data=json.dumps(login_values), headers=headers )
if r.status_code == 200:
return r.cookies
else:
raise ValueError(json.loads(r.text)['Message'])
auth_url="https://www.example.com/login"
username="testuser"
password="wrongpass"
starttime = time.time() * 1000
try:
cookie = login( auth_url, username, password )
print "Login succeeded, got cookie :-)"
except:
print "Failed to login!"
endtime = time.time() * 1000
print "Time in milliseconds: ", endtime-starttime
linux可以用:
time curl -H "Content-Type: application/json" -X POST -d '{"username":"admin","password":"wrongpass"}' https://www.example.com/login
© Sh4dow's Blog | Powered by LOFTER