I am sending a HTTP
POST
request using python
socket:
import socket
s = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 4001))
s.send(b'POST /session HTTP/1.1\r\nContent-Type:application/json\r\nUser-Agent: test/1\r\n\r\n{"desiredCapabilities": {}, "capabilities":{}}')
response = s.recv(10000)
print(response)
Output:
b'HTTP/1.1 200 OK\r\ncontent-length: 270\r\nContent-Type: application/json; charset=utf-8\r\nConnection: close\r\n\r\n{"sessionId":"72418bd14689c1cd9ee48706eada96a4","status":33,"value":{"message":"session not created exception: Missing or invalid capabilities\\n (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Linux 4.4.0-91-generic x86_64)"}}'
Summary of output - error message is returned saying that the json
object I am trying to send is missing or not correct.
This is why I decided to capture the request with
mitmproxy
.
It has no content, while it should have the following json
content:
{"desiredCapabilities": {}, "capabilities":{}}
I can't understand what the problem is. I followed the HTTP
specification - after each header I put CRLF
(\r\n
) and after the last header(User-Agent) I put additional CRLF
since there must be 1 empty row before body content.
The request/status line and headers must all end with
<CR><LF>
(that is, a carriage return followed by a line feed). The empty line must consist of only<CR><LF>
and no other whitespace.