static def lemp(String aKey,String userName,String tType){
def temp
try {
def ret = null
def http = new HTTPBuilder("http://192.168.1.10:8080/Pay-0.1/main/msgPicTemp")
http.parser.'text/html' = http.parser.'text/plain'
http.request(Method.GET, ContentType.TEXT) {
uri.query = [ appKey:appKey, userName:userName,tempType:tempType]
headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4'
response.success = { resp,reader -> println resp.status
println reader.text
temp=reader.text//i got error here,how to assign this to one variable and pass it to controller
}
response.failure = { resp -> println "Unexpected error: ${resp.status} : ${resp.statusLine.reasonPhrase}" }
}
return temp
} catch (groovyx.net.http.HttpResponseException ex) {
ex.printStackTrace()
return null
} catch (java.net.ConnectException ex) {
ex.printStackTrace()
return null
}
}
这里读者给出的代码如
<link rel="stylesheet" href="/Pay-0.1/static/css/bootstrap.css" type="text/css">
<div align="left" style="background-color:#B8B8B8;width:150px">
</div>
Welcome
如何将此阅读器分配给一个变量并返回到控制器。我想从控制器显示这一页。
答案 0 :(得分:4)
我认为问题出在您的println reader.text
上。从流中读取将关闭流。所以你的下一行,设置变量是行不通的。移除println reader.text
,看看是否还有问题