python - 对谷歌的http请求返回空的python套接字
问题描述
我试图向谷歌发送一个 http 请求,但我收到的都是空的 (b"")。这是我的代码:
import socket
target_host = "www.google.com"
target_port = 80
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((target_host, target_port))
print("Connected...")
request = "GET / HTTP/1.1\r\nHost:%s\r\n\r\n" % target_host
response = client.recv(4096)
http_response = repr(response)
http_response_len = len(http_response)
print("[+RECV+] - length %d" % http_response_len)
print(http_response)
这是我的回应:
[+RECV+] - length 3
b''
(完成请求也需要 240 秒,这正常吗?)谢谢!
解决方案
我的错,我忘了发送数据
client.send(request.encode())
推荐阅读
- google-cloud-source-repos - Google Cloud Source Repositories:更改默认分支?
- apache-camel - 如何在异常时停止骆驼动态路由
- shell - 在部署之前检查 GCloud 项目的脚本
- python - 优化计算正态分布的 NumPy 脚本
- typescript - 交集类型如何与多态 this 和泛型结合使用?
- python - RuntimeError: 标量类型 Double 的预期对象,但在调用 _th_max 时为参数 #2 'other' 获得了标量类型 Float
- python - 如果列名在列表中,则将数据框中的列一起添加
- azure - Azure Active Directory 撤销给定 aad app-id 的一组用户会话
- pandas - 在另一列熊猫上删除具有特定条件的重复值
- discord - 如何使用 python3 存储不和谐成员?