1

I am working on the springboot application where I need to add a header to request API where they used org.springframework.http.HttpHeaders to set the Header values to the request.

I can see they used below code for setting the string value header.

HttpHeaders headers = new HttpHeaders();
    headers.set("correlationId", "12232324545x32321");

My requirement is to add a header named x-ms-documentdb-partitionkey and it expect the value as an array:

x-ms-documentdb-partitionkey = ["file1"]

How can set the above using using the HttpHeaders. I refer the below the Javadocs. I could not able to figure out the right way to do.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/HttpHeaders.html

Thanks

1

2 Answers 2

1

HTTP headers are just name-value pairs (as strings). Consequently, you can just set this array in the required representation as the value. Don't forget to escape " properly.

HttpHeaders headers = new HttpHeaders();
headers.set("correlationId", "12232324545x32321");
headers.set("x-ms-documentdb-partitionkey", "[\"file1\"]");

System.out.println(headers);
[correlationId:"12232324545x32321", x-ms-documentdb-partitionkey:"["file1"]"]
Sign up to request clarification or add additional context in comments.

Comments

1

Try to write [ and ] explicte in the value

HttpHeaders headers = new HttpHeaders();
    headers.set("x-ms-documentdb-partitionkey", "[\"file1\"]");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.