2

I am trying to fetch some files from internet. I want to update my schedule service if the last modified time update. With HTTPBuilder I am unable to find the server response with last-modified parameter. Is there any way to get this parameter?

Opal
  • 81,889
  • 28
  • 189
  • 210
Cool Java guy מוחמד
  • 1,687
  • 4
  • 24
  • 40

1 Answers1

3

As in the docs Last-Modified is a header and should be searched among other headers. What's important is that it's server that decides if Last-Modified header will be included in the response. Hence, if the server you connect to doesn't return the header in the response it's impossible to get the value.

Headers can be obtained via response object, see below:

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1') 

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT

def http = new HTTPBuilder( 'http://www.google.com/search' )

http.request(GET,TEXT) { req ->
    response.success = { res ->
        res.headers.each { h ->
            println h
        }
    }
}
Opal
  • 81,889
  • 28
  • 189
  • 210