我使用AJAX这样的数据发送到golang应用:如何使用golang解析POST AJAX数据?
httpRequest = new XMLHttpRequest();
if (!httpRequest) {
document.getElementById("errorArea").innerText = "Giving up :(Cannot create an XMLHTTP instance'";
}
url = "http://127.0.0.1:8080/putContent?url="+window.location.pathname;
httpRequest.onreadystatechange = sendContents;
httpRequest.open('POST', url);
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var fd = new FormData();
fd.set ("data",document.getElementById("ta").value);
httpRequest.send(fd);
和后端是这样的:
r.ParseForm()
fmt.Print("postform=")
fmt.Println(r.PostForm)
结果(与sdfsdf键入到textarea的TA):
postform=map[------WebKitFormBoundarytZ4Y8wFVKpWBWBnu
Content-Disposition: form-data:[] name:["data"
sdfsdf
------WebKitFormBoundarytZ4Y8wFVKpWBWBnu--
]]
------------
编辑
发现的problem.The问题是FORMDATA发送数据curl -H 'Content-type: application/x-www-form-urlencoded' --data $'------WebKitFormBoundaryiVVK2EjSLDbqaccx\r\nContent-Disposition: form-data; name="data"\r\n\r\nsdfsdf\r\n------WebKitFormBoundaryiVVK2EjSLDbqaccx--\r\n' --compressed
,而不是`卷曲--data“数据= sdfsdf”
现在,真正的问题是如何如何得到FORMDATA发送正常数据?