Call getPage from htmlunit WebClient with JavaScript disabled and setTimeout set to 10000 waits forever

天涯浪子 提交于 2019-11-28 12:42:59

     _thewebclient.setWebConnection(new HttpWebConnection(_thewebclient) {
     @Override
     protected synchronized AbstractHttpClient getHttpClient() {
         AbstractHttpClient client = super.getHttpClient();
         if (_TimeoutCliSocket > 0) {
             //Sets the socket timeout (SO_TIMEOUT) in milliseconds to
             //be used when executing the method.
             //A timeout value of zero is interpreted as an infinite timeout.
             //Time that a read operation will block for, before generating 
             //an java.io.InterruptedIOException
             client.getParams().setParameter("http.socket.timeout", 
                                                      _TimeoutCliSocket);
         }
         if (_TimeoutCliConnection > 0) {
             //The timeout in milliseconds used when retrieving an
             // HTTP connection from the HTTP connection manager.
             // Zero means to wait indefinitely.
             client.getParams().setParameter("http.connection-manager.timeout", 
                                                     _TimeoutCliConnection);
         }
         client.getParams().setParameter("http.tcp.nodelay", true);
         return client;
     }
 });

Bye

I found, with HttpUnit 1.6.2 setting these

    final HttpClient client = new HttpClient();
    final GetMethod method = new GetMethod(pUrl);

    client.setConnectionTimeout((int) timeout);
    client.setTimeout((int) timeout);

    final int statusCode = client.executeMethod(method);

Seemed to do the trick. Both are deprecated methods. :(

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!