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

前端 未结 2 1926
迷失自我
迷失自我 2020-12-19 19:04

I\'m having problems with Htmlunit, I disabled JavaScript and set timeout to 10000 before calling getpage, I expected an exception after timeout but htmlunit waits forever.<

2条回答
  •  不知归路
    2020-12-19 19:51

         _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

提交回复
热议问题