惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cloudbric
Cloudbric
V
Visual Studio Blog
L
LangChain Blog
A
About on SuperTechFans
B
Blog
T
Tenable Blog
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Palo Alto Networks Blog
U
Unit 42
WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
C
Check Point Blog
Security Latest
Security Latest
M
MIT News - Artificial intelligence
Application and Cybersecurity Blog
Application and Cybersecurity Blog
宝玉的分享
宝玉的分享
P
Proofpoint News Feed
NISL@THU
NISL@THU
Forbes - Security
Forbes - Security
S
Securelist
Security Archives - TechRepublic
Security Archives - TechRepublic
Hugging Face - Blog
Hugging Face - Blog
aimingoo的专栏
aimingoo的专栏
Latest news
Latest news
GbyAI
GbyAI
T
Troy Hunt's Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LINUX DO - 热门话题
V2EX - 技术
V2EX - 技术
小众软件
小众软件
Google DeepMind News
Google DeepMind News
K
Kaspersky official blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
Netflix TechBlog - Medium
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed

博客园 - 哈哈

cas服务器搭建后的调整 request的url地址 numpy的多项式函数与求导 pandas相关 tcp与ip的包结构 江苏铁路 易经-64卦 使用python实现rpc服务 图书分类-中图法,值得一看的图书 linux时区,curl的使用,nginx日志,watch 使用selenium模仿登录,执行js python与java的交互 计算斐波那契数列 Python线程 selenium的使用 pip使用 python读取postgresql 18位身份证的验证码 python读取docx文件属性-最后一次保存的时间等
使用python直接连接http服务器获取数据
哈哈 · 2021-06-07 · via 博客园 - 哈哈

代码如下

import socket

SPLIT_LINE = '\r\n'


def connect(host, port, req_url):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, port))
    sd = 'GET ' + req_url + ' HTTP/1.1' + SPLIT_LINE
    sd = sd + get_header(host, port)
    sd = sd + SPLIT_LINE
    s.send(sd.encode())
    data = s.recv(1024)
    print(data)
    while True:
        data2 = s.recv(1024)
        if not data2:
            break
        print(data2)
    s.close()


def get_header(host, port):
    s = 'Accept:text/html,application/xhtml+xml,application/xml'+SPLIT_LINE
    s = s + 'Accept-encoding:gzip, deflate, br' + SPLIT_LINE
    s = s + 'Accept-Language:zh-CN,zh;q=0.9' + SPLIT_LINE
    s = s + 'Cache-Control:max-age=0' + SPLIT_LINE
    s = s + 'Connection:keep-alive' + SPLIT_LINE
    s = s + 'Host:' + host + ':' + str(port) + SPLIT_LINE
    s = s + 'User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36' + SPLIT_LINE
    return s


if __name__ == '__main__':
    req_url = '/hello/world'
    connect('localhost', 8080, req_url)