python - HTTP request content empty -


i sending 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 returned saying json object trying send missing or not correct.

this why decided capture request mitmproxy.

enter image description here

it has no content, while should have following json content:

{"desiredcapabilities": {}, "capabilities":{}} 

i can't understand problem is. followed http specification - after each header put crlf(\r\n) , after last header(user-agent) put additional crlf since there must 1 empty row before body content.

wiki http message body

the request/status line , headers must end <cr><lf> (that is, carriage return followed line feed). empty line must consist of <cr><lf> , no other whitespace.

the post request send missing content-length header, i.e. request send invalid. due missing content-length header server unable know body ends , might assume there no body @ all, i.e. far expected. reflected in comment: "in summary response saying json object missing".

i recommend use existing http library instead of trying use socket directly. http more complex developers think.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -