# CURL command with java ProcessBuilder errors for curl option usage

**URL:** <https://discuss.elastic.co/t/curl-command-with-java-processbuilder-errors-for-curl-option-usage/366721>\
**Category:** Elasticsearch\
**Created:** [September 18, 2024, 10:08am UTC](https://discuss.elastic.co/t/curl-command-with-java-processbuilder-errors-for-curl-option-usage/366721 "2024-09-18T10:08:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RSaravanaPrasad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rsaravanaprasad/32/137435_2.png) [@RSaravanaPrasad](https://discuss.elastic.co/u/RSaravanaPrasad)\
**Post date:** [September 18, 2024, 10:08am UTC](https://discuss.elastic.co/t/curl-command-with-java-processbuilder-errors-for-curl-option-usage/366721/1 "2024-09-18T10:08:21Z")

</div>

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

> **[Strict Content-Type Checking for Elasticsearch REST Requests](https://www.elastic.co/blog/strict-content-type-checking-for-elasticsearch-rest-requests)**
>
> Elasticsearch 6.0 will enforce strict content-type checking. All REST requests that include a body must also provide the correct Content-Type header....

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](https://www.elastic.co/guide/en/elasticsearch/reference/8.13/security-api-change-password.html#security-api-change-password-request) , **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](https://www.elastic.co/blog/strict-content-type-checking-for-elasticsearch-rest-requests) 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](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](https://www.elastic.co/guide/en/elasticsearch/reference/8.13/security-api-change-password.html#security-api-change-password-request)

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}

---

<div class="post-metadata">

**Author:** ![Chris\_Owens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_owens/32/57329_2.png) [@Chris\_Owens](https://discuss.elastic.co/u/Chris_Owens)\
**Post date:** [October 1, 2024, 1:26pm UTC](https://discuss.elastic.co/t/curl-command-with-java-processbuilder-errors-for-curl-option-usage/366721/2 "2024-10-01T13:26:43Z")

</div>

Category updated on October 1, 2024, 1:26pm UTC

From #Elastic Security to #Elasticsearch

---

<div class="post-metadata">

**Author:** ![Chris\_Owens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_owens/32/57329_2.png) [@Chris\_Owens](https://discuss.elastic.co/u/Chris_Owens)\
**Post date:** [October 1, 2024, 1:27pm UTC](https://discuss.elastic.co/t/curl-command-with-java-processbuilder-errors-for-curl-option-usage/366721/3 "2024-10-01T13:27:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 29, 2024, 1:27pm UTC](https://discuss.elastic.co/t/curl-command-with-java-processbuilder-errors-for-curl-option-usage/366721/4 "2024-10-29T13:27:27Z")

</div>

Closed on October 29, 2024, 1:27pm UTC

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