403请求中未包含有效的碎屑

问题描述 投票:0回答:1

我正在运行Spring Boot Application并尝试使用“spring-boot-starter-test”测试应用程序。在测试Web服务时,我收到状态代码为403的响应 - 请求中未包含有效的crumb。我无法弄清楚请求中缺少什么。我可以通过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)
spring spring-boot http apache-httpclient-4.x
1个回答
0
投票

通过删除“spring-boot-starter-test”和“httpclient”依赖项,我能够解决这个问题。现在我正在使用“放心”来测试Web服务。

© www.soinside.com 2019 - 2024. All rights reserved.