Answer the question
In order to leave comments, you need to log in
Why does curl -I (--head) return a 404 code, but curl -i returns a 200 code?
Actually, in the curl command, both -I and -i switches must return a response code. But in my case, they (response codes) are different for some reason.
Through the browser everything works fine.
Answer the question
In order to leave comments, you need to log in
curl 127.0.0.1 -I
[email protected]:~$ nc -l 8081
HEAD / HTTP/1.1
Host: 127.0.0.1:8081
User-Agent: curl/7.64.0
Accept: */*
[email protected]:~$ nc -l 8081
GET / HTTP/1.1
Host: 127.0.0.1:8081
User-Agent: curl/7.64.0
Accept: */*
and if you add User-Agent ? something like
curl -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0" blah blah
curl -I http://ya.ru 2>/dev/null | head -n 1 | cut -d$' ' -f2
curl -i http://ya.ru 2>/dev/null | head -n 1 | cut -d$' ' -f2
Depending on the libraries and technologies used, the HEAD handler may also need to be explicitly written. Therefore, it is not surprising that the server is not required to return the same.
For example, here I have a script written a hundred years ago based on the BaseHTTPServer library:
def do_GET(self):
url = self.path
for mm in self.methodmap.keys():
if re.match(mm, url):
return self.methodmap[mm](url, None)
self.send_response(404)
self.send_header('Content-Type', 'text/plain')
self.end_headers()
self.wfile.write('URL not defined')
def do_HEAD(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question