1

我在 groovy 中有以下代码

HTTPBuilder http = new HTTPBuilder("https://ronna-afghan.harmonieweb.org/_layouts/searchrss.aspx")



        http.request(Method.GET, groovyx.net.http.ContentType.XML) {

            // set username and password for basic authentication
            // set username and password for basic auth
            //http.auth.basic(ConfigurationHolder.config.passportService.userName,
            //        ConfigurationHolder.config.passportService.password)
            headers.'User-Agent' = 'Mozilla/5.0'

            uri.query = [k:'execution']

            // response handler for a success response code:
            response.success = {resp, xml ->
                println resp.statusLine



                log.debug "response status: ${resp.statusLine}"
                log.debug xml.toString()

            }

            // handler for any failure status code:
            response.failure = {resp ->
                log.error " ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
            }


        }

当我运行代码时,它没有给我我想得到的 rss 提要

当我在java中有相同的代码时

try {
            // Create a URLConnection object for a URL
            URL oracle = new URL(
                    "https://ronna-afghan.harmonieweb.org/_layouts/srchrss.aspx?k=execution&count=1&format=rss");

            URLConnection yc = oracle.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    yc.getInputStream()));
            String inputLine;

            while ((inputLine = in.readLine()) != null) {
                System.out.println(inputLine);
                in.close();
            }

        } catch (Exception e) {
            e.printStackTrace();

        }
    }

它返回 xml Rss。我想不出问题可能是什么。在 groovy 代码中,一切对我来说都很好,而且 Http 返回码是 200。

4

1 回答 1

3

您在 Java 中描述的代码等效于 Groovy 中的以下代码:

def oracle = "https://ronna-afghan.harmonieweb.org/_layouts/srchrss.aspx?k=execution&count=1&format=rss".toURL().text
于 2012-02-20T02:30:34.793 回答