Open tiredsosha opened 2 years ago
Your JSON is invalid.
You need to escape the quotes.
Exampel 1 (invalid):
curl -X POST https://domain.de/loginJSON -H "Content-Type: application/json" -d "{"user": "manu", "password": "123"}"
Response: {"error":"invalid character 'u' looking for beginning of object key string"}
Exampel 2:
curl -X POST https://domain.de/loginJSON -H "Content-Type: application/json" -d "{\"user\": \"manu\", \"password\": \"123\"}"
Response: {"status":"you are logged in"}
Have fun!
omg, that's work, thanks.
I just don't understand why first one isn't working? It's valid json. I tried to read from file, send with python script. This is how json file looks like:
{ "name": "manu", "password": "123" }
Your JSON is invalid.
You need to escape the quotes.
Exampel 1 (invalid):
curl -X POST https://domain.de/loginJSON -H "Content-Type: application/json" -d "{"user": "manu", "password": "123"}"
Response:
{"error":"invalid character 'u' looking for beginning of object key string"}
Exampel 2:
curl -X POST https://domain.de/loginJSON -H "Content-Type: application/json" -d "{\"user\": \"manu\", \"password\": \"123\"}"
Response:
{"status":"you are logged in"}
Have fun!
It reads in in as a string, which then is again placed in quotes.
So your JSON
{ "name": "manu", "password": "123" }
becomes:
"{ "name": "manu", "password": "123" }"
which now needs escaping for all inner quotes.
If you covert it in backticks
`{ "name": "manu", "password": "123" }`
you probably don't need to escape. But I recommend you escaping it.
@tiredsosha @MartinHotmann just by updating curl from
curl -X POST https://domain.de/loginJSON -H "Content-Type: application/json" -d "{"user": "manu", "password": "123"}"
to
curl -X POST http://localhost:8080/loginJSON -H "Content-Type: application/json" -d '{"user": "manu", "password": "123"}'
works perfectly. just replaced double quotes "
by single quote '
in -d
flag
Description
I tried my own variation + default from readme. Always the same error
{"error":"invalid character 'u' looking for beginning of object key string"}
To be honest i don't now wht to do anymore
How to reproduce
Environment