Look at the code:
var xmlhttp=getHTTPObject();
var post="test·test+test·";
xmlhttp.open('POST', 'test.asp?random='+Math.random(), true);
xmlhttp.setrequestheader("content-length",post.length);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200 ){
alert(xmlhttp.responseText);
return true;
}
}
xmlhttp.send("act="escape(post));
Here, I sent the string escape("test·test+test·") in POST mode, and used setRequestHeader.
When receiving it on the ASP side, I used
<%Response.CodePage=936%>
<%Response.Charset="gb2312"
Response.Write Unescape(Request("act"))
%>
Finally, after debugging, the result you see is that neither "·" nor "+" is displayed.
At first I thought it was the result of the incompatibility of escape and unescape in asp and javascript. Later I used vbsunescape (as shown below) instead of unescape and the problem remained the same.
<script language="javascript" runat="server">
function vbsunescape(source){
return unescape(source);
}
</script>
I escaped the +, but I don’t know how to do it. What did it convert into? I originally wanted to write it into a binary file to see (it must be a binary file), but I used stream to operate the binary file under asp. I keep making mistakes when creating files. I don’t have time to do this. There are still many things to do, so I’ll make do with some escaping for now. I’ll leave this problem to the experts who see this blog. If you solve it, let me know. Thanks!
function escape2(str){
return escape(str).replace(/+/g,"%2b");
}
-----------------------------------------------
I saw everyone’s replies, thank you all. After absorbing the essence of everyone's thoughts, I finally figured it out. . . .
The final perfect solution is that
the sender can use encodeURIComponent(escape(xxxxxxx)) (the other sending and receiving codes are the same as above).
I only tried encodeURI yesterday and did not think of the encodeURIComponent and escape socket methods. Suddenly just now I got inspired and tried it, it’s awesome, OHYEAH! Go eat! !