Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何中止HttpRequest?_Java_Httpclient_Exchangewebservices_Abort - Fatal编程技术网

Java 如何中止HttpRequest?

Java 如何中止HttpRequest?,java,httpclient,exchangewebservices,abort,Java,Httpclient,Exchangewebservices,Abort,我正在使用ThreadSafeClientConnManager管理HttpClient 4.0.1环境上的客户端连接池。 通常我的系统在使用NTLM进行身份验证时可以正常工作,但有时不能正常工作 当使用NTLM进行身份验证时,我们将按以下相同顺序接收结果代码:HTTP/1.1 401>HTTP/1.1 401>HTTP/1.1 200。 这是正确的过程 但是,我不知道为什么,有时候MS EWS会返回401结果代码3次:HTTP/1.1 401>HTTP/1.1 401>HTTP/1.1 401

我正在使用
ThreadSafeClientConnManager
管理HttpClient 4.0.1环境上的客户端连接池。 通常我的系统在使用NTLM进行身份验证时可以正常工作,但有时不能正常工作

当使用NTLM进行身份验证时,我们将按以下相同顺序接收结果代码:HTTP/1.1 401>HTTP/1.1 401>HTTP/1.1 200。 这是正确的过程

但是,我不知道为什么,有时候MS EWS会返回401结果代码3次:HTTP/1.1 401>HTTP/1.1 401>HTTP/1.1 401。 之后,EWS只为每个请求返回HTTP/1.1200

为了帮助你更好地理解

  • 用户A:401>401>200(良好)
  • 用户B:401>401>200(良好)
  • 用户C:401>401>401(出现问题)
  • 用户D:200
  • 用户E:200
  • 用户F:200
所以,当问题出现时,UserC,D,E,F。。。可以正确使用我们的系统

以下是我的问题

  • 为什么EWS在返回401三次后只返回200代码
  • 当我一直收到结果代码HTTP/1.1 401时,如何中止连接 更详细地说,

  • 为什么EWS在返回401三次后只返回200代码?但这种情况并不经常发生。用于身份验证的用户名和密码正确

  • 当我收到第三个HTTP/1.1 401时,如何中止连接? 我使用了
    request.abort()
    ,但它不起作用

  • 我的代码如下

        private Response processRequest(AbstractHttpClient httpClient, HttpRequestBase httpRequest, HttpContext httpContext){
        Response response = new Response();
    
        try {
            // execute request
            HttpResponse httpResponse = null;
            if(httpContext != null){
                httpResponse = httpClient.execute(httpRequest, httpContext);
    
                // retrieve cookie
                CookieStore cookieStore = (CookieStore)httpContext.getAttribute(ClientContext.COOKIE_STORE);
                List<Cookie> cookieList = cookieStore.getCookies();
                for(Cookie cookie : cookieList){
                    com.XXX.mo.connectivity.info.http.Cookie newCookie = new com.XXX.mo.connectivity.info.http.Cookie(cookie.getName(), cookie.getValue());
                    newCookie.setVersion(cookie.getVersion());
                    newCookie.setDomain(cookie.getDomain());
                    newCookie.setPath(cookie.getPath());
                    response.addCookie(newCookie);
                }
            }else{
                httpResponse = httpClient.execute(httpRequest);
            }
    
            // retrieve header
            response.setStatusCode(httpResponse.getStatusLine().getStatusCode());           
            Header [] headers = httpResponse.getAllHeaders();
            for(Header header : headers){
                response.addHeader(new com.XXX.mo.connectivity.info.http.Header(header.getName(), header.getValue()));
            }
    
            // retrieve body
            HttpEntity httpEntity = httpResponse.getEntity();
            if(httpEntity != null){
                response.setContentCharSet(EntityUtils.getContentCharSet(httpEntity));
                response.setBody(EntityUtils.toByteArray(httpEntity));
                httpEntity.consumeContent();
            }
        } catch (Exception e) {
            e.printStackTrace();
            httpRequest.abort();
        }
    
        return response;
       }
    
    私有响应processRequest(AbstractHttpClient httpClient,HttpRequestBase httpRequest,HttpContext HttpContext){
    响应=新响应();
    试一试{
    //执行请求
    HttpResponse HttpResponse=null;
    if(httpContext!=null){
    httpResponse=httpClient.execute(httpRequest,httpContext);
    //检索cookie
    CookieStore CookieStore=(CookieStore)httpContext.getAttribute(ClientContext.COOKIE_存储);
    List cookieList=cookieStore.getCookies();
    用于(Cookie Cookie:cookieList){
    com.XXX.mo.connectivity.info.http.Cookie newCookie=new com.XXX.mo.connectivity.info.http.Cookie(Cookie.getName(),Cookie.getValue());
    newCookie.setVersion(cookie.getVersion());
    newCookie.setDomain(cookie.getDomain());
    newCookie.setPath(cookie.getPath());
    addCookie(newCookie);
    }
    }否则{
    httpResponse=httpClient.execute(httpRequest);
    }
    //检索标题
    response.setStatusCode(httpResponse.getStatusLine().getStatusCode());
    Header[]headers=httpResponse.getAllHeaders();
    用于(标题:标题){
    response.addHeader(新的com.XXX.mo.connectivity.info.http.Header(Header.getName(),Header.getValue());
    }
    //取回尸体
    HttpEntity HttpEntity=httpResponse.getEntity();
    if(httpEntity!=null){
    response.setContentCharSet(EntityUtils.getContentCharSet(httpEntity));
    response.setBody(EntityUtils.toByteArray(httpEntity));
    httpEntity.consumerContent();
    }
    }捕获(例外e){
    e、 printStackTrace();
    httpRequest.abort();
    }
    返回响应;
    }