问题描述
我正在将htmlunit与spring test一起使用,以便从Web应用程序测试所有ihm接口。 html格式(post和get)和ajax get都可以正常工作,但是我对ajax post请求有问题。
控制器未收到请求。如果我替换为junit测试用例,则工作正常。
这是html视图
<html lang="fr" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Spring Html Unit</title>
<Meta charset="utf-8" />
<Meta name="format-detection" content="telephone=no">
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script>
function posttest() {
$.ajax({
type:"post",data: {
'subject' : 'subject test','message' : 'message test'
},url:"[[@{/test/post}]]",success: function(data,textStatus,jqXHR){
$("#result").text(data);
}
});
}
</script>
</head>
<body>
<h4 th:text="'Hello to Thymeleaf '+${myParam}">Hello from Thymeleaf</h4>
<button type="button" onClick="posttest()">Test post</button>
<div>
<span>result :</span><span id="result"></span>
</div>
</body>
和控制器
@控制器 公共类WelcomeController {
@GetMapping("/")
public String init(Model model) {
model.addAttribute("myParam","Guillaume");
return "welcome";
}
@PostMapping("/test/post")
public @ResponseBody String post(@RequestParam String subject,@RequestParam String message,Model model) {
return subject + " " + message;
}
}
您还可以在我的github https://github.com/guisimon28/spring-test-htmlunit
上找到完整的代码。您能帮我找到是否缺少某些配置,或者它是否是htmlunig错误或请求请求吗?
感谢所有人
纪尧姆
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)