2012-02-17 22 views
1

我有下面的代码常规常规HTTP生成器没有返回结果

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

回答

3

你在Java中所描述的代码是下面的代码在Groovy相当于:

def oracle = "https://ronna-afghan.harmonieweb.org/_layouts/srchrss.aspx?k=execution&count=1&format=rss".toURL().text 
+0

有道理。它的工作现在。我有从配置文件中读取的URL,它有一个错字。由此获得失败。这两个代码都返回正确的结果。 – allthenutsandbolts 2012-02-21 18:16:52

+1

您是否可以说提供的答案是给出问题细节问题的可接受答案? :) – 2012-02-21 19:41:48

+0

是的,我已经标记了它 – allthenutsandbolts 2012-02-21 19:52:18