- 论坛徽章:
- 0
|
python网络编程初次接触,怎么都弄不好啊感觉,求大神。
想用http.client模块来发送GET命令,如下:
GET http://public-ott-nodrm.verimatr ... &t=VOD&p=37 HTTP/1.1
Host: public-ott-nodrm.verimatrix.com:12684
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
Cookie: __utma=109597698.709692872.1387240809.1392717232.1392789859.8; __utmz=109597698.1387240809.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); wp4253="XVYWDs-lM-kim-TTvYTTTTTTW8nVs-TYCM:YYMDtlnDl-TXZK-UXTVDDDSSU-TUTLWBDSSU-TVZTYKDOLkptHmkpQ_Jht"
我照猫画虎如下:
import os,sys,urllib,socket
import http.client
conn = http.client.HTTPConnection('public-ott-nodrm.verimatrix.com',12684)
body = {'r':'gladiator1','t':'VOD','p':'37'}
headers = {"Host": "public-ott-nodrm.verimatrix.com:12684","Connection": "keep-alive","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36","Accept-Encoding": "gzip,deflate,sdch",
"Accept-Language": "zh-CN,zh;q=0.8,en;q=0.6"}
conn.request('GET','/CAB/keyfile',body,headers)
r = conn.getresponse()
r.read()
似乎不对啊,求大神指点。
如果改用socket发送,还是不对,如下:
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect(('public-ott-nodrm.verimatrix.com',12684))
msg = '''GET http://public-ott-nodrm.verimatr ... &t=VOD&p=37 HTTP/1.1 \n\n
Host: public-ott-nodrm.verimatrix.com:12684\n
Connection: keep-alive \n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\n
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36\n
Accept-Encoding: gzip,deflate,sdch\n
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6\n
Cookie: __utma=109597698.709692872.1387240809.1392717232.1392789859.8; __utmz=109597698.1387240809.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); wp4253="XVYWDs-lM-kim-TTvYTTTTTTW8nVs-TYCM:YYMDtlnDl-TXZK-UXTVDDDSSU-TUTLWBDSSU-TVZTYKDOLkptHmkpQ_Jht\n"'''
msg = msg.encode()
sock.send(msg)
res = sock.recv(500)
print("%s" %res)
大神帮忙改改,不胜感激。 |
|