title: How to get Response Body when Server responds with 302 in Grails?
body: <p>I want to request server side an image from a different server with a GET request. If the requesting server response with status code 200 everything works fine.
  But often I get FOUND 302 redirect as status code. In this case there is no <strong>response.body</strong> which I need.</p>
  
  <p>This is the code I use to retrieve a user image from facebook. Since facebook makes a redirect I get 302 as status code and not response.body.</p>
  
  <pre><code>def uri = new URI("http://graph.facebook.com/1000345345345/picture?width=200&amp;height=200")
  def requestFactory = new SimpleClientHttpRequestFactory()
  
  def request = requestFactory.createRequest(uri, HttpMethod.GET)
  
  try {
          def response = request.execute()
          def statusCode = response.statusCode
          if (statusCode == HttpStatus.FOUND) {
              log.debug "302" 
              // how do I get the response body?
          }
  
          if (statusCode == HttpStatus.OK) {
              return response.body.bytes
          }
          else if(statusCode == HttpStatus.FORBIDDEN) {
              throw new IllegalAccessError(response.statusCode.toString())
          }
  } catch(ex) {
      log.error "Exception while querying $url", ex
  }
  return null
  </code></pre>
  
  <p><strong>How do I get the correct response body in case on 302?</strong></p>