spring - 403 请求中没有包含有效的面包屑
问题描述
我正在运行一个 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)
解决方案
我能够通过删除“spring-boot-starter-test”和“httpclient”依赖项来解决这个问题。现在我正在使用“放心”来测试 Web 服务。
推荐阅读
- javascript - 如何在 javascript 循环中创建批处理以选择 x 行,然后选择下 x 行,直到所有行都完成?
- c# - 如何更改 XAML 样式文件中的颜色
- go - 在 go wiki 中解释 go 接口定义
- applescript - 获取 Finder 应用程序版本列的值
- android - 如何使用新 Places API 中的 AddressComponents?
- javascript - 更改 svg 元素中的字符串(文本元素)
- azure-devops - .NET Core 3.0 P9 的 Azure 管道不起作用
- ios - 无法解析回调缓存,中止恢复
- next.js - Next.js 中的控制标头
- html - 在 div 和输入中对齐文本的问题