1

我关注了这篇关于如何指定超时的帖子,做了:

def http = new HTTPBuilder(restEndpointUrl);
http.getParams().setParameter("http.socket.timeout", new Integer(2000))

我得到了错误:

Class: groovy.lang.MissingMethodException
Message:No signature of method: groovyx.net.http.HTTPBuilder.getParams() is applicable for argument types: () values: [] Possible solutions: getParser(), getClass(), getHeaders(), getUri()

我可能将其设置在错误的课程上,但如果您直接知道我做错了什么,您的评论将不胜感激。我对 Groovy/Grails 还很陌生。

谢谢

4

2 回答 2

1

您在底层客户端上设置计时器...

http.getClient().getParams().setParameter("http.socket.timeout", new Integer(2000))
于 2013-07-18T18:03:36.673 回答
0

试试这个,我正在使用带有 Grails 2.3.9 的 http-builder 0.7.1 插件:

import groovyx.net.http.HTTPBuilder
import org.apache.http.client.config.RequestConfig
import org.apache.http.config.SocketConfig
import org.apache.http.conn.ConnectTimeoutException
import org.apache.http.impl.client.HttpClients

def timeout = 10000
SocketConfig sc = SocketConfig.custom().setSoTimeout(timeout).build()
RequestConfig rc = RequestConfig.custom().setConnectTimeout(timeout).setSocketTimeout(timeout).build()
def hc = HttpClients.custom().setDefaultSocketConfig(sc).setDefaultRequestConfig(rc).build()        
def http = new HTTPBuilder(restEndpointUrl)
http.client = hc
于 2016-03-12T23:17:32.377 回答