I came across an odd HTTP request in my Apache access log:
"GET www.example.com HTTP/1.0"
Using a browser (Waterfox, Firefox or Chrome, (in that order)) or PuTTY/cURL|Terminal how can I reproduce this HTTP request? Preferably for localhost
as I can see the logs in real-time.
I did some reading and apparently cURL can only make absolute URL requests. I also have not been able to reproduce this with Edit and Resend in the Network panel of Waterfox. This request triggered some minor errors I wish to fix in my system.
First install Telnet.
Then copy and paste the following into a terminal window:
telnet localhost 80
GET www.example.com HTTP/1.0
Press Enter two times.
This is what it looks like in my access logs:
::1 - - [30/Oct/2020:23:37:28 -0700] "GET www.example.com HTTP/1.0" 400 310
You can also do this with PHP. Here is a file I created called test.php:
<?php
$fp = stream_socket_client("tcp://localhost:80", $errno, $errstr, 30) or die("$errstr ($errno)");
$request = "GET www.example.com HTTP/1.0\r\n\r\n";
$written = 0;
do {
$bytes = fwrite($fp, substr($request, $written)) or die('fwrite error');
$written+= $bytes;
}
while ($written!==strlen($request));
fclose($fp) or die('fclose error');
echo 'Request sent successfully';
exit;
The above does the same thing it just uses PHP to do it. Create a PHP file with the above text, point your browser to it, it should say "Request sent successfully" and then check your access logs.
Edit:
If you need to use TLS then try the following instead. Again save as test.php and point your browser to this file:
$fp = fsockopen("tls://localhost", 443, $errno, $errstr, 30) or die("$errstr ($errno)");
$request = "GET www.example.com HTTP/1.0\r\n\r\n";
$written = 0;
do {
$bytes = fwrite($fp, substr($request, $written)) or die('fwrite error');
$written+= $bytes;
}
while ($written!==strlen($request));
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp) or die('fclose error');
echo 'Request sent successfully';
exit;