【问题标题】:In grails, my HTTPBuilder call the one rest URL that return a gsp page.How to display the gsp page?在 grails 中,我的 HTTPBuilder 调用返回 gsp 页面的一个 rest URL。如何显示 gsp 页面?
【发布时间】:2013-02-05 10:35:57
【问题描述】:

我有两个 grails 应用程序是 application1 和 application2。 application1 使用 HTTPBuilder 调用返回一个模板(gsp 页面)的 application2。如何在我的应用程序中显示 gsp 页面(响应)1.我得到状态代码 200。之后我将如何显示页面?如何返回该响应?

static def users(String akey,String userName){
        try {
           def ret = null
           def http = new HTTPBuilder("http://192.168.1.7:8080/Play0.1/main/userGroup")
           http.request(Method.POST, ContentType.HTML) {
               uri.query = [ aKey:aKey, userName:userName]
               headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
               response.success = { resp,html -> println resp.status


                 }
               response.failure = { resp -> println "Unexpected error: ${resp.status} : ${resp.statusLine.reasonPhrase}" }
           }
           return ret
       } catch (groovyx.net.http.HttpResponseException ex) {
           ex.printStackTrace()
           return null
       } catch (java.net.ConnectException ex) {
           ex.printStackTrace()
           return null
       }
   }

该用户操作返回一个 gsp 页面。

【问题讨论】:

  • “我得到状态码 302”是什么意思?
  • 我的回复状态
  • 那么,你需要回复html,对吧?
  • ya.now 我得到了 200 作为我的回应。

标签: grails groovy httpbuilder


【解决方案1】:

正如维基百科所说:

HTTP/1.1 302 Found
Location: http://www.iana.org/domains/example/

您应该按照Location标头获取内容。

您可以检查您的application2 是否重定向,并考虑在application2 中实现REST 设计以避免Web 服务中的重定向。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-29
    • 1970-01-01
    • 2019-05-18
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多