【发布时间】:2018-09-11 20:42:42
【问题描述】:
我是计算机网络的新手,我正在尝试制作自己的代理服务器。
但是当我将从客户端收到的请求发送到服务器时,我无法从服务器获得响应。我的代码在这里出现异常:
try:
# connect
serverSock.connect((hostName, 80))
# get the client's request
fp = open("requestCache.txt", "r")
message = fp.read()
fp.close()
# send to the target server
serverSock.send(message)
response = serverSock.recv(4096)
# send to the client
tcpCliSock.send(response)
except:
print('connect failed!')
serverSock.close()
以下是从客户端收到的请求
GET /www.baidu.com HTTP/1.1
Host: localhost:3009
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
【问题讨论】:
-
您是否尝试过查看抛出的异常(例如,除了 Exception as ex: print(ex))?
标签: python http networking server