我正在尝试使用javascriptxmlhttprequest传递一个相当大的base64字符串,并且在调试时,我能够正确编码,但是以某种方式到达服务器时,它的某些部分(例如“ +”字符)丢失了。很多次,我还会收到500个内部服务器错误。其他时间,它在服务器端中断。这是我的代码:
function markAttendanceSuccess(fingerPacket,id,senderId,fromDate,toDate,leave)
{
var xhttp=new XMLHttpRequest();
xhttp.open("POST","myUrl",true);
xhttp.onload=function()
{
if(this.status===200)
{
var response=this.responseText;
let index=response.indexOf(">")+1;
response=response.substring(index,response.length);
index=response.indexOf(">")+1;
let index2=response.lastIndexOf("<");
response=response.substring(index,index2).toLowerCase();
if(response==="attendance marked successfully")
{
alert("success");
}
else
{
alert(response);
}
}
else {
alert(this.statusText);
}
}
xhttp.onerror=function()
{
alert(this.responseText);
}
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
let loginModel=JSON.parse(sessionStorage.getItem("loginModel"));
let str="";
str=fingerPacket+"~"+senderId+"~1~1~01-jan-1900~01-jan-1900~0";
}
str=btoa(str);
xhttp.send("parameter="+str);
}