IHP-无法从请求正文中检索特殊字符
我正在尝试使用AJAX发送请求:
const formBody = document.getElementById('body'); // my form data
const XHR = new XMLHttpRequest();
const params = "body=" + formBody;
XHR.open("POST", window.origin + '/CreateFormAction');
XHR.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
XHR.send(params);
相应的IHP操作:
action CreatePostAction = do
rBody <- getRequestBody
putStrLn $ tshow rBody -- this returns: ""
renderPlain "Request Received"
当我尝试发送诸如'$','+'等的特殊字符时,这是我在服务器上收到的请求:
POST /CreatePostMessage
Params: [("body"," ")]
Request Body: body=+
Accept: */*
Status: 200 OK 0.025023s
I'm trying to send the request using ajax:
const formBody = document.getElementById('body'); // my form data
const XHR = new XMLHttpRequest();
const params = "body=" + formBody;
XHR.open("POST", window.origin + '/CreateFormAction');
XHR.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
XHR.send(params);
The corresponding IHP action:
action CreatePostAction = do
rBody <- getRequestBody
putStrLn $ tshow rBody -- this returns: ""
renderPlain "Request Received"
When I try sending special characters like '$', '+', etc., this is the request I get on server:
POST /CreatePostMessage
Params: [("body"," ")]
Request Body: body=+
Accept: */*
Status: 200 OK 0.025023s
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用
encodeuricomponent()
对FormBody进行编码,以编码特殊字符,如下所示:您的IHP操作应该能够处理特殊字符。
You have to encode the formBody using
encodeURIComponent()
to encode special characters as follows:Your IHP action should be able to handle special characters then.