title: Reading HTTP headers in a Spring REST controller
body: <p>I am trying to read HTTP headers in Spring based REST API. I followed <a href="https://stackoverflow.com/questions/19556039/spring-mvc-controller-rest-service-needs-access-to-header-information-how-to-do">this</a>. But I am getting this error:</p>
  
  <blockquote>
    <p>No message body reader has been found for class java.lang.String,<br>
    ContentType: application/octet-stream</p>
  </blockquote>
  
  <p>I am new to Java and Spring so can't figure this out.</p>
  
  <p>This is how my call looks like:</p>
  
  <pre><code>@WebService(serviceName = "common")
  @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
  @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
  public interface CommonApiService {
  
      @GET
      @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
      @Produces(MediaType.APPLICATION_JSON)
      @Path("/data")
      public ResponseEntity&lt;Data&gt; getData(@RequestHeader(value="User-Agent") String userAgent, @DefaultValue ("") @QueryParam("ID") String id);
  }
  </code></pre>
  
  <p>I have tried <code>@Context</code>: HTTPHeader is <code>null</code> in this case.</p>
  
  <p>How to get values from HTTP headers?</p>