NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle+80 views

Что нужно сделать с файловым дескриптором сокета, чтобы отправить HTTP-запрос?

Practice

AI answer

First, connect the socket to the server, then send the bytes of the HTTP request through it using send() or sendall() (or the write() system call). The file descriptor itself is only an identifier for the socket; you do not need to pass it to the HTTP server. For example:

sock.connect((host, 80))
request = b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n"
sock.sendall(request)

It is important to format the request with the correct CRLF separators and an empty line at the end of the headers. For HTTPS, pass the request through a TLS socket before sending it.