All Projects → atlas-comstock → http_client

atlas-comstock / http_client

Licence: other
A http client written in C and pure socket, for understanding HTTP protocol. 用于理解 http 协议的 http 客户端

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to http client

Baselibrary
🔥Android开发 常用基础公共库(mvp/mvvm/retrofit/rxjava/socket/ble/多语言) 直接下载或依赖即可使用
Stars: ✭ 243 (+800%)
Mutual labels:  socket
SilentServer
Silent is very lightweight, high quality - low latency voice chat for gaming. The server runs on Windows and Linux.
Stars: ✭ 52 (+92.59%)
Mutual labels:  socket
NNet
algorithm for study: multi-layer-perceptron, cluster-graph, cnn, rnn, restricted boltzmann machine, bayesian network
Stars: ✭ 24 (-11.11%)
Mutual labels:  study
Sockpp
Modern C++ socket library.
Stars: ✭ 246 (+811.11%)
Mutual labels:  socket
MelonJS-Node-Socket.IO-Boilerplate-Example
A multiplayer melonJS + node.js + socket.io game
Stars: ✭ 28 (+3.7%)
Mutual labels:  socket
cmil
CMIL - Clarified Multilingual Intermediate Language
Stars: ✭ 32 (+18.52%)
Mutual labels:  study
Ssokit Qmake
A Simple & Strong Tool for TCP&UDP Debug
Stars: ✭ 231 (+755.56%)
Mutual labels:  socket
PortAuthority
🚢A simple and flexible Flask web app to scan ports on any IP address or domain
Stars: ✭ 14 (-48.15%)
Mutual labels:  socket
CentrifugoBundle
📦 Provides communication with web-socket server Centrifugo in Symfony applications.
Stars: ✭ 65 (+140.74%)
Mutual labels:  socket
BruteSniffing Fisher
hacking tool
Stars: ✭ 24 (-11.11%)
Mutual labels:  socket
Delphi Cross Socket
Delphi cross platform socket library
Stars: ✭ 250 (+825.93%)
Mutual labels:  socket
cpp20-internet-client
An HTTP(S) client library for C++20.
Stars: ✭ 34 (+25.93%)
Mutual labels:  socket
spring-study-sprout
🌱 11번가 새싹 신입들의 스프링 정복기 🚀
Stars: ✭ 180 (+566.67%)
Mutual labels:  study
Unitysocketprotobuf3demo
主要实现了用Unity对接了Leaf服务器。其次带了些小工具。
Stars: ✭ 244 (+803.7%)
Mutual labels:  socket
procbridge
A super-lightweight IPC (Inter-Process Communication) protocol over TCP socket.
Stars: ✭ 118 (+337.04%)
Mutual labels:  socket
Chattt
❯❯❯ Chat without leaving your terminal
Stars: ✭ 239 (+785.19%)
Mutual labels:  socket
AlgoSSAFY
삼성 청년 SW 아카데미 4기 서울 알고리즘 스터디 🔥🧑‍💻🔥
Stars: ✭ 14 (-48.15%)
Mutual labels:  study
micrOS
micrOS - mini automation OS for DIY projects requires reliable direct communication
Stars: ✭ 55 (+103.7%)
Mutual labels:  socket
malware api class
Malware dataset for security researchers, data scientists. Public malware dataset generated by Cuckoo Sandbox based on Windows OS API calls analysis for cyber security researchers
Stars: ✭ 134 (+396.3%)
Mutual labels:  study
call user func
A benchmark study of call_user_func()
Stars: ✭ 19 (-29.63%)
Mutual labels:  study

http_client

A http client written in C and pure socket, for understanding HTTP protocol. 用于理解 http 协议的 http 客户端

我们想想浏览器做了什么事情, 根据 url, 请求对方服务器, 获取相应的文件.

  1. 根据输入的 url 地址, 解析出 hostname. 如 根据https://stackoverflow.com/questions/tagged/elixir, hostname 为 stackoverflow.com, 其他的不过是 URL 的一部分. 程序中的extract_hostname 函数便是做这个事情
  2. 把 hostname 解析成 ip 地址, 我的函数·getIPFromDNS 便是做这个事情, 主要调用 linux 的 gethostbyname 即可解析dns, 得到一个ip 数组, 通常选一个即可.
  3. 我的函数init_serv_addr配置 socket 的信息, 如使用 ipv4, 用80端口, 访问哪个 ip .
  4. 连接 socket, generate_request_header 生成 http request 头部, 注意第一行即描述了使用GET 协议, HTTP 1.1 版本, HOST 是必须的, 因为大多数 web 服务器都设置了虚拟主机, 也就是根据 HOST 来 redirect 你到不同的 地方.
  5. 收对方的回复, 收到response 的头部后(根据\r\n\r\n 划分), 解析出 Content-Length, 接着收剩下的内容~ 至此, 一个简单的 http client 完成.

示例: http://example.com 解析到的 ip 地址为: IP ADDRESS->93.184.216.34

-> HTTP请求报文如下

--------HTTP Request--------
GET / HTTP/1.1
HOST: example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
Cache-Control: no-cache

服务器response回复的头部为:

HTTP/1.1 200 OK
Cache-Control: max-age=604800
Content-Type: text/html
Date: Thu, 21 Jun 2018 10:35:29 GMT
Etag: "1541025663+ident"
Expires: Thu, 28 Jun 2018 10:35:29 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (oxr/8313)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1270

接着的内容是:

<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

    }
    div {
        width: 600px;
        margin: 5em auto;
        padding: 50px;
        background-color: #fff;
        border-radius: 1em;
    }
    a:link, a:visited {
        color: #38488f;
        text-decoration: none;
    }
    @media (max-width: 700px) {
        body {
            background-color: #fff;
        }
        div {
            width: auto;
            margin: 0 auto;
            border-radius: 0;
            padding: 1em;
        }
    }
    </style>
</head>

<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is established to be used for illustrative examples in documents. You may use this
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].