The Content-Type header is just used as info for your application. The browser doesn't care what it is. The browser just returns you the data from the AJAX call. If you want to parse it as JSON, you need to do that on your own.

The header is there so your app can detect what data was returned and how it should handle it. You need to look at the header, and if it's application/json then parse it as JSON.

This is actually how jQuery works. If you don't tell it what to do with the result, it uses the Content-Type to detect what to do with it.

Answer from gen_Eric on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Response › json_static
Response: json() static method - Web APIs | MDN
This live example shows how you can create a JSON response object, and logs the newly created object for inspection (the logging code is hidden as it is not relevant). ... const logElement = document.getElementById("log"); function log(text) { logElement.innerText += `${text}\n`; } async function logResponse(response) { const responseText = await response.text(); log(`body: ${responseText}`); response.headers.forEach((header) => log(`header: ${header}`)); log(`status: ${response.status}`); log(`statusText: ${response.statusText}`); log(`type: ${response.type}`); log(`url: ${response.url}`); log(`ok: ${response.ok}`); log(`redirected: ${response.redirected}`); log(`bodyUsed: ${response.bodyUsed}`); }
🌐
Informatica
docs.informatica.com › reference material › rest api reference › informatica intelligent cloud services rest api › header and body configuration › json format example
JSON format example
You can then use the sessionId and the baseapiUrl to construct a request to obtain your organization's license information, for example: GET https://https://usw3.dm-us.informaticacloud.com/saas/public/core/v3/license/org/52ZSTB0IDK6dXxaEQLUaQu Content-Type: application/json Accept: application/json INFA-SESSION-ID: 9KA11tLGqxVcGeul8SQBK3 · Header and body configuration ·
🌐
Atlassian
developer.atlassian.com › server › crowd › json-requests-and-responses
JSON requests and responses
curl -i -u application_name:application_password --data '{"value": "my_password"}' http://localhost:8095/crowd/rest/usermanagement/1/authentication?username=my_username --header 'Content-Type: application/json' --header 'Accept: application/json' ... { "reason" : "INVALID_USER_AUTHENTICATION", ...
🌐
Progress
documentation.progress.com › output › Corticon › 5.6.1 › html › corticon › sample-json-request-and-response-messages.html
Sample JSON request and response messages
Evaluation of a request will look ... and if not found, it will look for it as an HTTP header. The Decision Service payload is enclosed in the request message's body in the JSON object form. The JSON object structure is specified in a separate document. You must specify the Decision Service name in the HTTP header field dsname, as shown in this example for ...
Top answer
1 of 5
44

Yes, you may use JSON in HTTP headers, given some limitations.

According to the HTTP spec, your header field-body may only contain visible ASCII characters, tab, and space.

Since many JSON encoders (e.g. json_encode in PHP) will encode invisible or non-ASCII characters (e.g. "é" becomes "\u00e9"), you often don't need to worry about this.

Check the docs for your particular encoder or test it, though, because JSON strings technically allow most any Unicode character. For example, in JavaScript JSON.stringify() does not escape multibyte Unicode, by default. However, you can easily modify it to do so, e.g.

var charsToEncode = /[\u007f-\uffff]/g;
function http_header_safe_json(v) {
  return JSON.stringify(v).replace(charsToEncode,
    function(c) {
      return '\\u'+('000'+c.charCodeAt(0).toString(16)).slice(-4);
    }
  );
}

Source

Alternatively, you can do as @rocketspacer suggested and base64-encode the JSON before inserting it into the header field (e.g. how JWT does it). This makes the JSON unreadable (by humans) in the header, but ensures that it will conform to the spec.


Worth noting, the original ARPA spec (RFC 822) has a special description of this exact use case, and the spirit of this echoes in later specs such as RFC 7230:

Certain field-bodies of headers may be interpreted according to an internal syntax that some systems may wish to parse.

Also, RFC 822 and RFC 7230 explicitly give no length constraints:

HTTP does not place a predefined limit on the length of each header field or on the length of the header section as a whole, as described in Section 2.5.

2 of 5
18

Base64encode it before sending. Just like how JSON Web Token do it.
Here's a NodeJs Example:

const myJsonStr = JSON.stringify(myData);
const headerFriendlyStr = Buffer.from(myJsonStr, 'utf8').toString('base64');
res.addHeader('foo', headerFriendlyStr);

Decode it when you need reading:

const myBase64Str = req.headers['foo'];
const myJsonStr = Buffer.from(myBase64Str, 'base64').toString('utf8');
const myData = JSON.parse(myJsonStr);
🌐
Google Cloud
cloud.google.com › cloud storage › http headers and common query string parameters for json
HTTP headers and common query string parameters for JSON | Cloud Storage | Google Cloud Documentation
The JSON API uses the following query string parameters: A request header that contains a string used to authenticate requests. A response header that indicates the caching directive for the request. An optional identifier in the part-header of a multipart request. The length (in bytes) of the request or response body. A header used in some upload requests and download responses.
🌐
ReqBin
reqbin.com › req › 4rwevrqh › post-json-example
How do I post JSON to the server?
January 16, 2023 - To post JSON data to the server, ... body and pass the "Content-Type: application/json" request header. The Content-Type request header specifies the media type for the resource in the body.
🌐
Baeldung
baeldung.com › home › web › sending json http request body in terminal
Sending JSON HTTP Request Body in Terminal | Baeldung on Linux
March 18, 2024 - In this tutorial, we’ll be learning how to send JSON objects as the request body correctly with the help of the Content-Type HTTP header. In Linux, curl and wget are the common terminal-based HTTP clients. Given its popularity in the Linux ecosystem, we’ll be using them in this article for demonstration purposes. To obtain curl and wget, we can install them using the package manager. For example...
Find elsewhere
🌐
BrowserStack
browserstack.com › guide › api-headers-and-body
What are API Headers and Body?
June 19, 2025 - BrowserStack created a detailed guide section that educates users about the latest testing trends, types of testing environments, setups & more. Explore!
🌐
Stack Overflow
stackoverflow.com › questions › 50482813 › body-and-header-with-post-data
json - body and header with post data - Stack Overflow
Explore Stack Internal ... let bodydata = JSON.stringify({ fonk: 'usrlogin', login_userid: '111111', passsha:'d4c59285sds62233bc232e0f205esd8b7e' }); let bodydata1 = "fonk=usrlogin&login_userid=111111&passsha=d4c59285sds62233bc232e0f205esd8b7e" ...
🌐
Stack Overflow
stackoverflow.com › questions › 62374458 › how-to-have-a-header-body-json-schema-structure-and-validate-it
jsonschema - How to have a header/body json schema structure and validate it - Stack Overflow
For a better visualisation here is an example json: { "timestamp": "452366", "version": "2424", "actualData":{ "schemaId": "http://someDomain.com/schemas/bodyschema123", "dynamicData1":"foobar", "dynamicData2":"barfoo", // and so on } } How should ...
🌐
Tableau
help.tableau.com › current › api › rest_api › en-us › REST › rest_api_concepts_example_requests.htm
REST API Example Requests - Tableau
The first REST API request in a session must be a sign-in request. This is a POST request that sends the user credentials in the body of the request. Because this is a POST request, the request must include the Content-Type header. You can send your the body of the request block as XML or JSON.
🌐
Bubble
forum.bubble.io › need help › apis
How to put JSON object in header - APIs - Bubble Forum
January 22, 2021 - The REST API that I am trying to connect to requires a JSON authorization in the header. It is supposed to be in the format { “auth” : { “command” : “api.authenticate”, “params” : { “username”: “username@example.co…
🌐
freeCodeCamp
freecodecamp.org › news › what-is-the-correct-content-type-for-json-request-header-mime-type-explained
What is the Correct Content-Type for JSON? Request Header Mime Type Explained
September 4, 2024 - This means when you're sending JSON to the server or receiving JSON from the server, you should always declare the Content-Type of the header as application/json as this is the standard that the client and server understand.
🌐
JSONPlaceholder
jsonplaceholder.typicode.com › guide
JSONPlaceholder - Guide
fetch('https://jsonplaceholder.typicode.com/posts', { method: 'POST', body: JSON.stringify({ title: 'foo', body: 'bar', userId: 1, }), headers: { 'Content-type': 'application/json; charset=UTF-8', }, }) .then((response) => response.json()) .then((json) => console.log(json)); 👇 Output ·
Top answer
1 of 1
1

From what I understand you have changed the request format and now want the same request body to work for the same controller.

I think you were trying to add the fields to the header. What you are doing here is not the right way to do it. It should goes to header section rather than in the body section of the Postman app. But doing so, you will have to specify these header separately as these are custom headers which will be a lot of work.

Answer to your question

Going by what you were trying to do. Since now you have changed the request body. You will have to make changes in the controller class too. Now it will require three classes If you want to do it in a modular way.

The first class will be BodyRequest.java

private string validateClientRequest;
private string movil;

The next class will be HeaderRequest.java

private string country;
private string lang;
private string entity;
private string system;
private string subsystem;
private string operation;
private Date timestamp;
private string msgType;

Next class will be ValidateClientRequest.java

private HeaderRequest Header;
private BodyRequest Body;

Now for the RequestBodyDemo class;

private ValidateClientRequest ValidateClient;

Note : Use appropriate Getter and setter along with @JsonProperty if you are masking the input request data.

Once these things are done. In your controller Instead of using Entity in @RequestBody Use the class RequestBodyDemo. Once that is done. Just try printing the values just to check whether you are getting them right or not. Then use getter for fetching any value that you need.

Edit :

  public ResponseVo ValidateClient(@RequestBody  RequestBodyDemo req) {
        System.out.println(req.getValidateClient().getBodyrequest().getMovil()); 

        return dao.validarClienteBonifiado(req.getValidateClient().getBodyrequest().getMovil()); 
    }

Note : Use appropriate getter method here.

🌐
ReqBin
reqbin.com › req › 2xhbguy8 › json-payload-example
How do I send JSON Payload to the server?
January 13, 2023 - To send the JSON payload to the ... body and indicate the data type of the request body with the "Content-Type: application/json" request header. If the client expects a response from the server in JSON format, it also needs to send the "Accept: ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › HTTP › Headers › Content-Type
Content-Type header - HTTP | MDN
When forms don't involve file uploads and are using simpler fields, URL-encoded forms may be more convenient where the form data is included in the request body: ... <form action="/submit" method="post"> <label for="comment">Comment:</label> <input type="text" id="comment" name="comment" value="Hello!" /> <button type="submit">Submit</button> </form> ... POST /submit HTTP/1.1 Host: example.com Content-Type: application/x-www-form-urlencoded Content-Length: 16 comment=Hello! Many REST APIs use application/json as a content type which is convenient for machine-to-machine communication or programmatic interaction.