forked from utx201777/HttpServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
44 lines (33 loc) · 854 Bytes
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!E:\python\venv\Scripts
# -*- coding:utf-8 -*-
import socket
def post_request():
req = 'POST /?ni=00 HTTP/1.1\r\n'
req = req + 'Host: 127.0.0.1:9999\r\n\r\n'
req = req + 'name=linyi&data=163'
return req
def get_request():
req = 'GET / HTTP/1.1\r\n'
req = req + 'Host: 127.0.0.1:9999\r\n\r\n'
return req
def start_request():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', 9999))
req = get_request()
s.send(req)
buff = []
while True:
d = s.recv(1024)
if d:
buff.append(d)
else:
break
data = ''.join(buff)
s.close()
header, html = data.split('\r\n\r\n', 1)
f = open('res.html', 'w')
f.write(html)
f.close()
if __name__ == '__main__':
start_request()
input("press any key to exit;")