Rest_assured测试本地休息Web服务出错" java.net.ConnectException:连接被拒绝:connect"

时间:2017-08-03 05:33:51

标签: java rest-assured

我编写了一个非常简单的代码来访问我的本地Web API服务器并获得Connection refused错误。但Postmen或Fiddler工作正常,可以连接服务器并获得响应。

我的代码看起来像

Response resp=  get("https://localhost/Members");
System.out.println(resp.getStatusCode());

错误消息如下所示:

  

java.net.ConnectException:拒绝连接:connect at   java.net.DualStackPlainSocketImpl.connect0(Native Method)at   java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)     在   java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)     在   java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)     在   java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)     在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)at   java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)at   java.net.Socket.connect(Socket.java:589)at   sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)at   org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:532)     在   org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:409)     在   org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)     在   org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)     在   org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)     在   org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)     在   org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)     在   org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)     在   org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)     在org.apache.http.client.HttpClient $执行$ 0.call(未知来源)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)     在   com.jayway.restassured.internal.RequestSpecificationImpl $ RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:1974)     在   com.jayway.restassured.internal.http.HTTPBuilder.doRequest(HTTPBuilder.java:492)     在   com.jayway.restassured.internal.http.HTTPBuilder.request(HTTPBuilder.java:441)     在   com.jayway.restassured.internal.http.HTTPBuilder $请求$ 2.call(未知   来源)at   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)     在   com.jayway.restassured.internal.RequestSpecificationImpl.sendHttpRequest(RequestSpecificationImpl.groovy:1396)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)     在groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1210)at at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019)at at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)at at   com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)     在   com.jayway.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:1178)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)     在groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1210)at at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019)at at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)at at   com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)     在   com.jayway.restassured.internal.filter.SendRequestFilter.filter(SendRequestFilter.groovy:30)     at com.jayway.restassured.filter.Filter $ filter $ 0.call(Unknown Source)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)     at com.jayway.restassured.filter.Filter $ filter.call(Unknown Source)     在   com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:73)     在   com.jayway.restassured.filter.time.TimingFilter.filter(TimingFilter.java:56)     at com.jayway.restassured.filter.Filter $ filter.call(Unknown Source)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)     在   com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:73)     在com.jayway.restassured.filter.FilterContext $ next.call(未知   来源)at   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)     在   com.jayway.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1596)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)at   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)     在groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1210)at at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019)at at   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)at at   com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)     在   com.jayway.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy:160)     在   com.jayway.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy)     在com.jayway.restassured.RestAssured.get(RestAssured.java:808)

0 个答案:

没有答案