Reputation: 6532
I'm trying to get a request's http-accept header and I get different values when I get the header from
req.getHeader("Accept") + req.getHeader("Accept-Encoding") + req.getHeader("accept-language")
'<?php echo $_SERVER['HTTP_ACCEPT'].$_SERVER['HTTP_ACCEPT_ENCODING'].$_SERVER['HTTP_ACCEPT_LANGUAGE']; ?>
The results are :
*/*gzip,deflate,sdchen-US,en;q=0.8
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8gzip,deflate,sdchen-US,en;q=0.8
How come they are different?
Am I getting them wrong?
Upvotes: 1
Views: 287
Reputation: 279910
PHP is returning all of the request parameters while your Java HTTP client is only returning one.
The HttpServletRequest
method provides the getHeaders(String)
that
Returns all the values of the specified request header as an
Enumeration
ofString
objects.
So use that.
Notice how the Java result (split to account for the String
concatenation you are doing)
*/* */
^ the last 'Accept' header value
gzip,deflate,sdch
^ the 'Accept-Encoding'
en-US,en;q=0.8
^ the 'Accept-Language'
I'm not exactly sure why it doesn't do it for the other headers.
This would be much clearer from the start if your output was easier to read. Don't just concatenate Strings like that. Use a separator of some sort.
Upvotes: 1