CURL command with java ProcessBuilder errors for curl option usage

Processing Elastic API's change user password curl command with a java client.

mentions adding -H'Content-Type: application/json' for requests with body.
There is no space between -H option and the ' ( quote )

But when "Copy as curl" is used from Change passwords API | Elasticsearch Guide [8.13] | Elastic , there is a space between option -H and ' .

Please note when copied into this textarea the space is lost.

When copied to a notepad or an editor the space exists.

curl -X POST "localhost:9200/_security/user/jacknich/_password?pretty" -H 'Content-Type: application/json' -d'
{
"password" : "new-test-password"
}
'
Which is correct usage. With space or without space

Following are the errors with Content-Type specified as in Strict Content-Type Checking for Elasticsearch REST Requests | Elastic Blog without a space and with a space between -H option and ' using java client processing elastic API's change password CURL command with Java's ProcessBuilder ..

String curlPostCommand = {"curl", "-u",
"jacknich:password",
"-H 'Content-Type: application/json'",
"-X POST", "https://localhost:9200/_security/user/jacknich/_password",
"-d '{"password":"new-test-password"}'"};
..
..

ProcessBuilder builder = new ProcessBuilder(curlPostCommand);
..
..
try {
Process process = builder.start();

status:406 with -H'Content-Type: application/json' and

status:400 with -H 'Content-Type: application/json'

1) Following is error with no space in between -H'Content-Type: application/json'
curl POST result: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 119 100 97 100 22 87 19 0:00:01 0:00:01 --:--:-- 107100 119 100 97 100 22 87 19 0:00:01 0:00:01 --:--:-- 107{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

2) Following is error with a space in between -H 'Content-Type: application/json' as copied from Change passwords API | Elasticsearch Guide [8.13] | Elastic

curl POST result: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 368 100 346 100 22 357 22 0:00:01 --:--:-- 0:00:01 381{"error":{"root_cause":[{"type":"media_type_header_exception","reason":"Invalid media-type value on headers [Accept]"}],"type":"media_type_header_exception","reason":"Invalid media-type value on headers [Accept]","caused_by":{"type":"illegal_argument_exception","reason":"invalid media-type [/ 'Content-Type: application/json']"}},"status":400}

From Elastic Security to Elasticsearch

I moved your topic to a forum where I think you will have better luck getting an answer.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.