Creating a Simple Python HTTP Client

Опубликовано: 08 Август 2023
на канале: theurbanpenguin
2,254
86

In this video you will learn to create a simple HTTP client in Python which you can use to test HTTP connections and the success of server installs. Even though you can use curl or w3m from the Linux CLI, making use of your own Python 3 script helps you learn more about TCP connections and Python

import socket
import sys

def http_request(host, port):
http_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
http_client.connect((host, port))
http_client.send(b"GET / HTTP/1.1\r\nHost: " + host.encode() + b"\r\n\r\n")

response = http_client.recv(4096)

print(response.decode("utf-8"))

http_client.close()

if _name_ == "__main__":
if len(sys.argv) != 3:
print("Usage: python3 http.py host port")
else:
host = sys.argv[1]
port = int(sys.argv[2])
http_request(host,port)

Additionally you can find my video courses on Pluralsight: http://pluralsight.com/training/Autho... and take time to see my own site http://www.theurbanpenguin.com

00:00 Intro
01:19 Edit script
09:35 test script
11:45 test to Ubuntu server
12:16 test to Fedora server


На этой странице сайта вы можете посмотреть видео онлайн Creating a Simple Python HTTP Client длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь theurbanpenguin 08 Август 2023, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 2,254 раз и оно понравилось 86 зрителям. Приятного просмотра!