jjzjj

CloseableHttpResponse

全部标签

java - CloseableHttpResponse.close() 和 httpPost.releaseConnection() 有什么区别?

CloseableHttpResponseresponse=null;try{//dosomething....HttpPostrequest=newHttpPost("someurl");response=getHttpClient().execute(request);//dosomeotherthing....}catch(Exceptione){//dealwithexception}finally{if(response!=null){try{response.close();//(1)}catch(Exceptione){}request.releaseConnection

java - 如何创建 CloseableHttpResponse 对象来帮助测试?

我正在尝试构建一个CloseableHttpResponse要在我的单元测试之一中返回的模拟对象,但没有构造函数。我找到了这个DefaultHttpResponseFactory,但它只生成一个HttpResponse。构造CloseableHttpResponse的简单方法是什么?我是否需要在测试中调用execute()然后设置statusLine和entity?这似乎是一种奇怪的方法。这是我试图模拟的方法:publicstaticCloseableHttpResponsegetViaProxy(Stringurl,Stringip,intport,Stringusername,St