Python - Building a HTTP request string variable
python
Solution
You could use string formatting:
request = 'GET {path} HTTP 1.1\r\nHost: {host}\r\nConnection: Close\r\n\r\n'.format(path=path, host=host)
This uses the modern `str.format()` method, but you could use classic string operations as well.
Problem
I am trying to build the HTTP request string in the variable "full_req". Here is how a HTTP request looks: ``` GET /images/logo/ HTTP/1.1 Host: www.google.com Connection: close ``` I already wrote python code so if I enter a url, "http://www.google.com/images/logo/googlelogo.png", it will split the url into 3 parts. Below are the variables that I used: - `host` (contains `www.google.com`) - `path` (contains `/images/logo/`) - `file` (contains `googlelogo.png`) - `port` (Its showing `None` but I think its suppose to say `80`) How do I assign HTTP request string to full_req variable so if I print this variable, it contains all three lines? ``` print(full_req) ``` tried string concatenation but it didn't work. I used this resource: http://www.skymind.com/~ocrow/python_string/