java - 客户端休息 Api 不使用服务器中声明的方法
问题描述
我正在使用 rest jersey 开发签名应用程序,但客户端出现错误,它没有使用服务器应用程序中定义的功能。我找不到问题。
我的控制器:
@RequestMapping(value = { "/signpdf50" }, method = RequestMethod.POST)
@Consumes({"text/plain,text/html"})
@Produces("application/pdf")
public ResponseEntity<String> signPDF5(@RequestBody String pdf) throws Exception {...}
测试方法:
public static Response signPDF50(String pdf1) throws ClientProtocolException, IOException {
ClientConfig clientConfig = new ClientConfig();
HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("sam", "sam");
clientConfig.register(feature);
Client client = ClientBuilder.newClient(clientConfig);
Entity<String> pdf= Entity.json(pdf1);
Response response = client.target("http://localhost:8094/rubi/rest/signpdf50")
.request("application/pdf")
.accept(MediaType.APPLICATION_JSON).post(pdf);
System.out.println(response.getLocation());
return response;
}
当我调用此方法时,它总是给我null结果,并且没有任何反应,这意味着它没有使用该方法。
字符串pdf是一个字节数组,在调用方法之前编码为字符串,然后在控制器中解码。
在控制器中
@RestController
@ComponentScan
@RequestMapping("/rest")
public class SigningControllerREst {
...
}
我试过 System.out.println(response.readEntity(String.class));
<html><head><title>Login Page</title></head><body onload='document.f.username.focus();'>
<h3>Login with Username and Password</h3><form name='f' action='/rubi/login' method='POST'>
<table>
<tr><td>User:</td><td><input type='text' name='username' value=''></td></tr>
<tr><td>Password:</td><td><input type='password' name='password'/></td></tr>
<tr><td colspan='2'><input name="submit" type="submit" value="Login"/></td></tr>
<input name="_csrf" type="hidden" value="bbff729a-34e6-465c-a86b-0f521a927ccd" />
</table>
</form></body></html>
在application.properties我添加了这两行进行身份验证
spring.security.user.name=sam
spring.security.user.password=sam
谢谢你的帮助。
解决方案
推荐阅读
- ios - 点击一个 UIView 到全屏,然后再次点击回到小尺寸
- apache-spark - PySpark 将时间(仅)与时间变量进行比较
- rust - 我怎么知道在 Rust 中没有调用 drop() 的原因?
- c - 如何在 C 中使用指针返回值?
- javascript - 出现错误:测试 webhook 错误:尝试将测试事件发送到 webhook 端点时出现 400
- android - 在开放测试模式下发布应用后,Firebase 身份验证不起作用
- javascript - 阻止事件传播到同一 Web 组件的另一个实例?
- html - 有没有办法使用 CSS 强制(打印模式)适合 1 页?
- html - 我如何获得
- c# - 如何使用 StringBuilder 编辑动态创建的 HTML 表