when executed this command:
curl -H "Host:" http://127.0.0.1
it response 400 Bad request.
from http rfc:
If the requested URI does not include an Internet host name for the service being requested, then the Host header field MUST be given with an empty value.
why?
Because -H "Host:" removes the header altogether. See the docs for -H, --header <header/#file>:
[...] Remove an internal header by giving a replacement without content on the right side of the colon, as in: -H "Host:". If you send the custom header with no-value then its header must be terminated with a semicolon, such as -H "X-Custom-Header;" to send "X-Custom-Header:".
You need -H "Host;" to send an empty host header.
Related
I have a curl request
curl --proxy 'http://proxy_host:4000' --url 'http://url.com'
How do I translate this into a valid Http Message? I'm unsure of how to structure it and which headers I need to use.
This question already has answers here:
How does a HTTP Proxy utilize the HTTP protocol? a Proxy RFC?
(3 answers)
Closed 2 years ago.
I run the cmd:
curl http://fbvn.org --proxy 171.229.106.254:21217
=> It works
But:
curl http://171.229.106.254:21217 -H 'host: fbvn.org' -H 'connection: close'
Or
curl http://171.229.106.254:21217/http://fbvn.org -H 'host: fbvn.org' -H 'connection: close'
Both don't work and get error: 'Invalid header received from client.'
I don't know why, am I missing any http header?
Yes, how to communicate via a HTTP proxy is defined in the HTTP protocol spec. The client then connects to the proxy and asks that for the remote URL.
One way to see how curl does it, is to add --trace-ascii dump.txt to the command line and it'll save the entire request and response for you to investigate and learn from.
curl -I gives 503 error while curl -v gives 200.
What can be the root cause?
eg-
curl -I -k https://myurl
HTTP/1.1 503 Service Unavailable
curl -k -v https://myurl
HTTP/1.1 200 OK
The root cause is the server being stupid and it doesn't like HEAD requests although it should. As RFC 7231 section 4.3.2 says about HEAD:
The server SHOULD send the same header fields in response to a HEAD
request as it would have sent if the request had been a GET, except
that the payload header fields MAY be omitted.
I am sending the following request via command line osx
curl -X POST "http://thing.com/feeds/auth" -d "username=name" -d "password=password"
I am receiving a message as follows:
<authentication status="passed">
<timestamp timeZone="EST">20140317194754</timestamp>
</authentication>
I need to capture the cookie that is created when i authenticate so I can use if for further requests. How would I do this?
Thanks!
Use the parameter --dump-header to save the header into a file. From there you can get the cookie. It will be beside the response header Set-Cookie:
--dump-header /var/tmp/xyz/header.txt
I would like to POST (send) some form data to a webserver using cURL on a terminal-prompt.
This is what I got so far:
curl --data-ascii "content=derinhält&date=asdf" http://myserverurl.com/api/v1/somemethod
The problem is that the umlaute ("äöü") are replaced by "?" when I receive the post request on the server.
I think I need to use an UTF-8 encoding for the POST request.
Does anybody know how I can achieve this?
You CAN use UTF-8 in the POST request, all you need is to specify the charset in your request.
You should use this request:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded; charset=utf-8" --data-ascii "content=derinhält&date=asdf" http://myserverurl.com/api/v1/somemethod