save cookies from curl auth post - unix

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

Related

How do I structure a proxy http message?

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.

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.

How to send a POST request using HTTPie?

I have a basic silex application, and I try to test it using HTTPie. Yet when posting using:
http POST http://localhost:1337 data="hello world"
The data, that I get from the Request object via:
$data = $request->request->get('data');
will always be empty. What is the problem here?
It was an httpie usage problem as the form flag was necessary, as silex requires the parameters to be form-encoded, yet the default of HTTPie is to pass a JSON object.
$ http --form POST http://localhost:1337 data="hello world"
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: close
Content-Type: application/json
Date: Wed, 14 Oct 2015 15:04:09 GMT
Host: localhost:1337
X-Powered-By: PHP/5.5.9-1ubuntu4.13
{
"message": "hello world"
}
Just to clarify what kOpernikus said, when you are making a POST request using httpie, use the following syntax:
http --form post :3000/register username="gilbert" password="stackoverflow!"
Alternatively, since forms are for post requests you can leave out post and also abbreviate --form to -f like so:
http -f :3000/register username=gilbert password=stackoverflow!
EDIT (thanks to Aerials)
To pass csrf token as header in the post request do:
http --form POST http://localhost:8000/login/ username=user password=pass X-CSRFToken:assQ$%auxASDLSIAJSd

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