我正在发出 ajax 发布请求,我可以看到该值正在客户端的标头中传递。
但是在服务器端收到的值是空白的?当服务器试图解析它时,它似乎被值中的某些东西阻塞了。因为如果我使用 encodeURIComponent 它工作正常。是什么导致了这种行为?
<script>
//var body = getDataFromTheEditor(); //doesn't work
//var body = JSON.stringify(getDataFromTheEditor()); //doesn't work
var body = encodeURIComponent(getDataFromTheEditor()); //works but don't want to do this...
var params = {body: body};
$.post("../../../../CommitEdit", $.param(params));
</script>
小服务程序:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String body = request.getParameter("body");
System.out.println(body); //blank if i pass it normally :(
}
我直接从标题中复制了表单数据,因为它正在传递(所以这里有一些服务器显然不喜欢的东西):
相关请求标头:
Content-Length: 64488 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
有任何想法吗?谢谢。
慕哥6287543
芜湖不芜
相关分类