我需要向Web服务器发送POST请求,并能够读取所述服务器发送的响应.我试着用这个代码使用HTTPBuilder lib:
def http = new HTTPBuilder('http://myServer/')
http.setProxy("Proxy_IP", 8080, "http")
postBody = [cmd:'e',format:'sep',c:'a',b:'b',t:'u',r:'r',kl:'lop']
http.post( body: postBody,
requestContentType: URLENC ){ resp ->
HttpEntity he = resp.getEntity()
println "${resp.getAllHeaders()}"
println he.getContentType()
println "${resp.getEntity().getContent()}"
}
Run Code Online (Sandbox Code Playgroud)
执行此代码时出现异常:
ERROR errors.GrailsExceptionResolver - EOFException occurred when processing request: [GET] /PROJECT/home/index
Unexpected end of ZLIB input stream. Stacktrace follows:
Message: Unexpected end of ZLIB input stream
Line | Method
->> 240 | fill in java.util.zip.InflaterInputStream
- - - - - - - - - - - - - …Run Code Online (Sandbox Code Playgroud)