0

I am trying to get body of GET request made using socket module but I am getting only headers even though I set up pretty big buffer size. Web application I reach is made on my own using Flask.

sockets.py

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 5000))
s.sendall(b'GET / HTTP/1.1\r\nHost:127.0.0.1\r\n\r\n')
print(s.recv(4096).decode('utf-8'))

app.py

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def main():
    return render_template('main.html')

main.html

<html>
    <body>
        <h1>Hello world</h1>
    </body>
</html>

Here is what I'm getting executing sockets.

HTTP/1.1 200 OK
Server: Werkzeug/2.1.2 Python/3.10.5  
Date: Sun, 07 Aug 2022 18:33:53 GMT   
Content-Type: text/html; charset=utf-8
Content-Length: 66
Connection: close

As you can see there is no body of the request. What am I doing wrong?

davidism
  • 121,510
  • 29
  • 395
  • 339

0 Answers0