3

I have a simple test PHP page:

<?php
  echo $_SERVER['HTTP_HOST'] . '<br/>';
  echo $_SERVER['REQUEST_URI'];
?>

When I access this page with a browser (I've tested chrome, and links) it gives me the output I'm expecting:

10.1.25.222
/test.php

But when I access this with curl 10.1.25.222/test.php:

10.1.25.222<br/>HTTP://10.1.25.222/test.php

Giving me the HTTP_HOST I'm expecting, but not the REQUEST_URI I'm expecting

grimetime
  • 143
  • 6

1 Answers1

2

I can only assume that curl must be sending the entire URL in its GET request. I've tested both methods below against Apache and they both appear to work and give similar results to what you are experiencing:

What most browsers seem to do in their HTTP request:

GET /some/path HTTP/1.1
Host: www.domain.com

What curl appears to be doing:

GET HTTP://www.domain.com/some/path HTTP/1.1
Host: www.domain.com
USD Matt
  • 5,381
  • 15
  • 23
  • Okay, do you have any idea why curl does that differently? – grimetime Jul 25 '13 at 15:27
  • Not really, I was surprised it worked - I though the `GET` line was supposed to only contain the 'file path' part of the URL. It's just the only way I can see for the entire URL to appear in `REQUEST_URI`. A wild guess would be some historic thing, possibly relating to attempts to support virtual hosting (allowing multiple domains on one server) before the HTTP 1.1 spec finalised the `Host` header. If you run `curl` with the `--verbose` or `--trace-ascii` options it should show exactly what it's sending. – USD Matt Jul 25 '13 at 15:34