Thursday, October 27, 2022

[SOLVED] 400 Bad Request: invalid header name with curl POST request

Issue

I am trying to make a post request to an elastic search endpoint. The api key is correct and I was taking reference from this link: href="https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html for the api key format. my curl request

curl -H "Authorization:ApiKey xxxxx" 
\ -H "Content-Type:application/x-ndjson 
-XPOST "https://712bbxxx/tttt/_bulk" 
--data-binary "@sss.json"

the error message:

curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
400 Bad Request: invalid header name

I am pretty sure the quotes symbol & the spacing should be correct. may I ask if you have any idea what's wrong?


Solution

Maybe you forgot to close quotes for the content-type header, try

-H "Content-Type:application/x-ndjson"


Answered By - Matthias
Answer Checked By - Timothy Miller (WPSolving Admin)