post request socket python

Solutions on MaxInterview for post request socket python by the best coders in the world

showing results for - "post request socket python"
Chrissy
03 Nov 2018
1import socket
2
3target_host = "www.google.com" 
4 
5target_port = 80  # create a socket object 
6client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
7 
8# connect the client 
9client.connect((target_host,target_port))  
10 
11# send some data 
12request = "GET / HTTP/1.1\r\nHost:%s\r\n\r\n" % target_host
13client.send(request.encode())  
14 
15# receive some data 
16response = client.recv(4096)  
17http_response = repr(response)
18http_response_len = len(http_response)
19 
20#display the response
21gh_imgui.text("[RECV] - length: %d" % http_response_len)
22gh_imgui.text_wrapped(http_response)
Roberta
16 Aug 2019
1from socket import socket,error
2headers = """GET http://www.google.com HTTP/1.1
3                Host: www.google.com\r\n\r\n"""
4try:
5  s = socket()
6  s.connect((host,int(port)))
7  s.settimeout(4)
8  s.send(headers.encode())
9  s.recv(800)
10  s.close()
11except error:
12  s.close()