Python socket SSL程序示例

#!/usr/bin/python
import socket
def fun(id,passwd,rang,time,op):
httpheader='''POST /ipgw/ipgw.ipgw HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: pyPKUIPGW Certificating Client version 0.1(Alpha)
Host: ipgw.pku.edu.cn\r\n''';

sk=socket.socket() #default
sk.connect(("162.105.67.5",443));
sslobj=socket.ssl(sk);

data="uid=%s&password=%s&range=%s&timeout=%s&operation=%s" %(id,passwd,rang,time,op)
content="Content-Length:%d\r\n\r\n"%(len(data),)
request="%s%s%s"%(httpheader,content,data)

print request

sslobj.write(request)
response=sslobj.read(40960);

print response

return response