我正在发出一个ajax post请求,我可以看到值正在客户端的头中传递。
但是,在服务器端,接收的值为空?当服务器试图解析该值时,它似乎被该值中的某些内容阻塞了。因为如果我使用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>
Servlet:
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 :(
}
在传递formdata时,我直接从报头复制了它(因此这里有一些服务器显然不喜欢的东西):
pastebin - unparsed formdata
pastebin - parsed formdata
Content-Length: 64488
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
有什么想法吗?谢谢