I'm using curl to post login information to a json API. I'm confused because the following two calls, which I thought were equivalent, are giving different results:
curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"username":"test@test.com","password":"secret"}' http://api.mysite.com/Services/v1/login.svc/login
This call results in a 400 Bad Request. However, if I put the login json into a file called "login.json", and change the call to:
curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d @login.json http://api.mysite.com/Services/v1/login.svc/login
Then the call works fine, gives a 200 results, and returns the expected json response.
Why is the first call not working?
Thanks!
Update for Rusty
I tried the following, both with and without single quotes surrounding the JSON:
curl -v -H "Accept: application/json" -H "Content-Type: application/json" --data-urlencode '{username:test@example.com,password:11111111}' "https://api.example.com/login"
But the data is not sent to the server. From curl's output:
Warning: Couldn't read data from file
Warning: "{username:test@example.com,password:11111111}", this makes an empty
Warning: POST.
and while the request did get a 200 OK response, the login, which works when I use the file method, still failed, presumably because the JSON is not being sent.