Are there any straightforward ways to make a HTTP request and get at the raw, unparsed response (specifically the headers)?
The Raw HTTP action sends a HTTP request to a web server. How the response is treated depends on the method, but in general the status code and the response headers are returned in variables defined as part of the page load options.
In order to extract a header from a response, you will have to use Http. request along with the expectStringResponse function, which includes the full response including headers. Here is an example on ellie-app.com which returns the value of content-type as an example.
Raw means that the header is not URL-encoded, whereas if the word "raw" is omitted, the header is encoded. For example: $header = 'http://www.mywebsite.com?
Using the socket module directly:
import socket
CRLF = "\r\n"
request = [
"GET / HTTP/1.1",
"Host: www.example.com",
"Connection: Close",
"",
"",
]
# Connect to the server
s = socket.socket()
s.connect(('www.example.com', 80))
# Send an HTTP request
s.send(CRLF.join(request))
# Get the response (in several parts, if necessary)
response = ''
buffer = s.recv(4096)
while buffer:
response += buffer
buffer = s.recv(4096)
# HTTP headers will be separated from the body by an empty line
header_data, _, body = response.partition(CRLF + CRLF)
print header_data
HTTP/1.0 302 Found
Location: http://www.iana.org/domains/example/
Server: BigIP
Connection: Keep-Alive
Content-Length: 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With