我正在运行Spring Boot应用程序,并尝试使用“ spring-boot-starter-test”测试该应用程序。测试Web服务时,我收到状态代码为403的响应-请求中未包含有效的屑。我无法找出请求中缺少的内容。我可以通过POSTMAN来测试服务,但是在单元测试期间相同的请求详细信息失败了。
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - >> "POST /new-game
HTTP/1.1[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - >> "Accept: */*[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - >> "Content-Type: application/json; charset=UTF-8[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - >> "Content-Length: 40[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - >> "Host: localhost:8080[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - >> "Connection: Keep-Alive[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - >> "User-Agent: Apache-HttpClient/4.5.7 (Java/1.8.0_144)[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - >> "Accept-Encoding: gzip,deflate[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - >> "[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - >> POST /new-game HTTP/1.1
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - >> Accept: */*
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - >> Content-Type: application/json; charset=UTF-8
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - >> Content-Length: 40
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - >> Host: localhost:8080
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - >> Connection: Keep-Alive
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - >> User-Agent: Apache-HttpClient/4.5.7 (Java/1.8.0_144)
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - >> Accept-Encoding: gzip,deflate
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - >> "{"firstMove":true,"playerName":"Adarsh"}"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - << "HTTP/1.1 403 No valid crumb was included in the request[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - << "Date: Sun, 31 Mar 2019 19:48:53 GMT[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - << "X-Content-Type-Options: nosniff[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - << "Cache-Control: must-revalidate,no-cache,no-store[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - << "Content-Type: text/html;charset=iso-8859-1[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - << "Content-Length: 389[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - << "Server: Jetty(9.4.z-SNAPSHOT)[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
2019-03-31 14:48:53 [main] DEBUG o.a.h.i.conn.DefaultClientConnection - Receiving response: HTTP/1.1 403 No valid crumb was included in the request
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - << HTTP/1.1 403 No valid crumb was included in the request
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - << Date: Sun, 31 Mar 2019 19:48:53 GMT
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - << X-Content-Type-Options: nosniff
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - << Cache-Control: must-revalidate,no-cache,no-store
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - << Content-Type: text/html;charset=iso-8859-1
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - << Content-Length: 389
2019-03-31 14:48:53 [main] DEBUG org.apache.http.headers - << Server: Jetty(9.4.z-SNAPSHOT)
答案 0 :(得分:0)
我能够通过删除“ spring-boot-starter-test”和“ httpclient”依赖项来解决此问题。现在,我使用“放心”来测试Web服务。