spring - How to get Response Body when Server responds with 302 in Grails? -


i want request server side image different server request. if requesting server response status code 200 works fine. found 302 redirect status code. in case there no response.body need.

this code use retrieve user image facebook. since facebook makes redirect 302 status code , not response.body.

def uri = new uri("http://graph.facebook.com/1000345345345/picture?width=200&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 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 

how correct response body in case on 302?

you can use this. method is:

def queryurl(url, ...) {}  

you can use:

        if (statuscode == httpstatus.found) {             def newurl = response.connection.responses.getheaders().location[0]             log.debug "302 redirect ${newurl}"             return queryurl(newurl, "")         } 

this request redirected url.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -