#spring #spring-boot #http #apache-httpclient-4.x
#spring #пружинный ботинок #http #apache-httpclient-4.x #spring-boot
Вопрос:
Я запускаю приложение Spring Boot и пытаюсь протестировать приложение с помощью «spring-boot-starter-test». Во время тестирования веб-служб я получаю ответ с кодом состояния 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)
Комментарии:
1. Я смог решить эту проблему, удалив зависимости «spring-boot-starter-test» и «httpclient».
Ответ №1:
Я смог решить эту проблему, удалив зависимости «spring-boot-starter-test» и «httpclient». Теперь я использую «rest-assured» для тестирования веб-сервисов.