放心:获取 org.apache.http.ConnectionClosed异常:内容长度分隔消息正文过早结束



我正在尝试在我的代码中使用原始主体调用"put"api调用,但是我收到以下错误

org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 69; received: 68
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:135)
at org.apache.http.conn.EofSensorInputStream$read.call(Unknown Source)
at io.restassured.internal.RestAssuredResponseOptionsGroovyImpl.convertStreamToByteArray(RestAssuredResponseOptionsGroovyImpl.groovy:470)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:149)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:100)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:208)
at io.restassured.internal.RestAssuredResponseOptionsGroovyImpl.charsetToString(RestAssuredResponseOptionsGroovyImpl.groovy:522)
at io.restassured.internal.RestAssuredResponseOptionsGroovyImpl$charsetToString$4.callCurrent(Unknown Source)
at io.restassured.internal.RestAssuredResponseOptionsGroovyImpl.asString(RestAssuredResponseOptionsGroovyImpl.groovy:183)
at io.restassured.internal.RestAssuredResponseOptionsGroovyImpl.asString(RestAssuredResponseOptionsGroovyImpl.groovy:179)
at io.restassured.internal.RestAssuredResponseOptionsImpl.asString(RestAssuredResponseOptionsImpl.java:234)
at com.NexusPortalAutomation.Utilities.Java.restAssured.cancelSpa(restAssured.java:70)
at com.NexusPortalAutomation.Utilities.Java.restAssured.test(restAssured.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

法典:

char q ='"';
RestAssured.baseURI = "http://localhost:3000/api/v1/spa/cancel/" + spaIndex;
String rawbody ="{"+q+"SpaCancel"+q+":[{"+q+"CustomerId"+q+":"+q+Customer+q+","+q+"SpaIndex"+q+spaIndex+q+"CancelDate"+q+":"+q+"2020-06-08"+q+","+q+"CancelReason"+q+":"+q+"Test"+q+","+q+"ReasonCode"+q+":"+q+" "+q+"}]}";
RequestSpecification httpRequest = RestAssured.given().headers("Authorization", "Bearer " + getToken(),
"Content-Type", ContentType.JSON, "Accept", ContentType.JSON) ;
Response response = httpRequest.body(rawbody).put();
String body = response.getBody().asString();
System.out.println(body);

我针对测试 PUT 端点测试了您的代码,它在我的机器上运行良好。我敢打赌,您看到的错误消息表明您的http://localhost:3000/api/v1/spa/cancel/响应有问题。如错误所示,内容长度与实际返回的内容不匹配。

我发现了这个问题,这是不正确的正文,因为在"SpaIndex"之后缺少":">

字符串 rawbody ="{"+q+"SpaCancel"+q+":[{"+q+"CustomerId"+q+":"+q+Customer+q+","+q+"SpaIndex"+q+spaIndex+q+"CancelDate"+q+":"+q+">

2020-06-08

"+q+","+q+"CancelReason"+q+":"+q+"Test"+q+","+q+"ReasonCode"+q+":"+q+" "+q+"}]}";

相关内容

  • 没有找到相关文章

最新更新