我需要使用 REST Assured API 自动化 REST API,但遇到问题。使用 REST Assured API,我需要使用 Spring Security 配置登录。
请看下面的代码:
@Before
public void configure() {
RestAssured.baseURI = "https://example.com";
RestAssured.basePath = "/my-portal";
}
@Test
public void apiLogin() {
given().auth().form("username", "password", springSecurity().withLoggingEnabled(new LogConfig())).when().get();
}
我面临的问题是:
实际请求 URI:https://example.com/j_spring_security_check
预期请求 URI:https://example.com/my-portal/j_spring_security_check
以下是获取的响应:
Request method: POST
Request URI: https://example.com/j_spring_security_check
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: j_username={username}
j_password={password}
Path params: <none>
Multiparts: <none>
Headers: Accept=*/*
Content-Type=application/x-www-form-urlencoded; charset=ISO-8859-1
Cookies: <none>
Body: <none>
HTTP/1.1 404 Not Found
Date: Mon, 06 Feb 2017 10:51:41 GMT
Content-Length: 0
Connection: close
Content-Type: text/plain