gpt4 book ai didi

rest - Groovy/Grails-通过使用HTTPBuilder获得HttpResponseException

转载 作者:行者123 更新时间:2023-12-02 14:41:26 27 4
gpt4 key购买 nike

我尝试从另一个Grails应用程序(MyApplication2)获取Grails应用程序(MyApplication2)的数据。两者都在本地运行。
我使用以下代码引发异常。

Groovy

try {
def http = new HTTPBuilder('http://localhost:8080/MyApplication2')

http.get( path : '/ControllerName/Action', contentType : ContentType.TEXT) { resp, reader ->

println "response status: ${resp.statusLine}"
resp.headers.each { h ->
println " ${h.name} : ${h.value}"
}

}
} catch (groovyx.net.http.HttpResponseException ex) {
ex.printStackTrace()
println ex.toString()

} catch (java.net.ConnectException ex) {
ex.printStackTrace()
println ex.toString()
}

抛出异常
 Error 2015-10-28 10:13:43,448 [http-bio-8090-exec-1] ERROR errors.GrailsExceptionResolver  - HttpResponseException occurred when processing request: [GET] /MyApplication1/ControllerName/Action Not Found.

最佳答案

我终于找到了问题:我更改了URI格式。
我在URI的末尾添加了/,并在/的开头删除了path

try {

def http = new HTTPBuilder('http://localhost:8080/MyApplication2/')

http.get( path : 'ControllerName/Action', contentType : ContentType.TEXT) { resp, reader ->

println "response status: ${resp.statusLine}"
resp.headers.each { h ->
println " ${h.name} : ${h.value}"
}

}
} catch (groovyx.net.http.HttpResponseException ex) {
ex.printStackTrace()
println ex.toString()

} catch (java.net.ConnectException ex) {
ex.printStackTrace()
println ex.toString()
}

关于rest - Groovy/Grails-通过使用HTTPBuilder获得HttpResponseException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33387753/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com