Skip to content

Instantly share code, notes, and snippets.

@ak-seyam
Last active January 31, 2020 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ak-seyam/f0f0794cacc8fb2ce9b184d380799af4 to your computer and use it in GitHub Desktop.
Save ak-seyam/f0f0794cacc8fb2ce9b184d380799af4 to your computer and use it in GitHub Desktop.
from socket import gethostbyname
def write_request(content_str
,host
,method="GET"
,path="/"
,content_type="application/json"
,new_line=r"\r\n"
,http_version="HTTP/1.1"
):
return method+" "+path+" "+http_version+new_line \
+"Host: "+host+new_line \
+"Content-Type: "+content_type+new_line \
+"Content-Length: "+str(len(content_str))+new_line*2 \
+content_str \
+new_line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment