How do I structure a proxy http message? - http

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.

Related

How does the client send data to the proxy server? Is it http protocol? [duplicate]

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.

API PLATFORM jwt access ignored

I ask for a token, it works :
POST auth-user.coi.im/login_check {"username": "reader", "password": "reader"}
{"token":
eyJ0eXAiOiJKV..........................................................." }
without token : it's ok ! i have the error message
auth-user.coi.im/api/users/1
{"code":401,"message":"JWT Token not found"}
with token :
auth-user.coi.im/api/users/1
Authorization Bearer eyJ0eXAiOiJKV...........................................................
Could not get any response
There was an error connecting to auth-user.coi.im/api/users/1.
or with curl and with token:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLC......................"
curl: (56) Recv failure: Connection was reset
HELP !
I have the same answer as if I put anything like url
why, does it work on my computer and not on a remote server?
If you use apache server, it will strip any Authorization header not in a valid HTTP BASIC AUTH format
Create a .htaccess file at the root of your project, and add this rule,
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
Found in the : jwt docs

HTTP Host Field with empty value, by response 400

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.

curl -I option not working

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.

How do I POST form data with UTF-8 encoding by using curl?

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

Resources