Posting time: 17:23:00
Function base64service (){
// Msxml2.xmlhttp. 3.0
// Msxml2.xmlhttp. 5.0
This. _ XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
This. _ xmldoc = new activexobject ("msxml2.domdocument ");
This. _ base64encodeurl = "./base64.asmx ";
This. _ base64encodemethodname = "encodeurl ";
This. _ base64encodeparametername = "url ";
This. _ base64decodemethodname = "decodeurl ";
This. _ base64decodeparametername = "url ";
}
Base64service. Prototype. encode = function (value ){
If (this. _ XMLHTTP = NULL | this. _ xmldoc = NULL ){
Alert ('method: encode; error: XMLHTTP or xmldoc is null! ');
Return '';
}
VaR data;
Data = '<? XML version = "1.0" encoding = "UTF-8"?> ';
Data = Data + '<soap: envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "http://www.blog.com.cn/http://www.w3.org/2001/XMLSchema" xmlns: Soap = "http://www.blog.com.cn/http://schemas.xmlsoap.org/soap/envelope/"> ';
Data = Data + '<soap: Body> ';
Data = Data + '<' + this. _ base64encodemethodname + 'xmlns = "http://tempuri.org/"> ';
Data = Data + '<' + this. _ base64encodeparametername + '>' + encodexml (value) + '</' + this. _ base64encodeparametername + '> ';
Data = Data + '</' + this. _ base64encodemethodname + '> ';
Data = Data + '</soap: Body> ';
Data = Data + '</soap: envelope> ';
Try {
This. _ XMLHTTP. Open ("Post", this. _ base64encodeurl, false );
This. _ XMLHTTP. setRequestHeader ("Content-Type", "text/XML; charset = gb2312 ");
This. _ XMLHTTP. setRequestHeader ("soapaction", "http://tempuri.org/" + this. _ base64encodemethodname );
This. _ XMLHTTP. Send (data );
This. _ xmldoc. loadxml (this. _ XMLHTTP. responsetext );
VaR node = this.w.xmldoc.doc umentelement;
Return node. text;
} Catch (e ){
Alert ('method: encode64; error: '+ E. Message );
Return '';
}
}
Base64service. Prototype. Decode = function (value)
{
If (this. _ XMLHTTP = NULL | this. _ xmldoc = NULL ){
Alert ('method: Decode; error: XMLHTTP or xmldoc is null! ');
Return '';
}
VaR data;
Data = '<? XML version = "1.0" encoding = "UTF-8"?> ';
Data = Data + '<soap: envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: XSD = "http://www.blog.com.cn/http://www.w3.org/2001/XMLSchema" xmlns: Soap = "http://www.blog.com.cn/http://schemas.xmlsoap.org/soap/envelope/"> ';
Data = Data + '<soap: Body> ';
Data = Data + '<' + this. _ base64decodemethodname + 'xmlns = "http://www.blog.com.cn/http://tempuri.org/"> ';
Data = Data + '<' + this. _ base64decodeparametername + '>' + value + '</' + this. _ base64decodeparametername + '> ';
Data = Data + '</' + this. _ base64decodemethodname + '> ';
Data = Data + '</soap: Body> ';
Data = Data + '</soap: envelope> ';
Try {
This. _ XMLHTTP. Open ("Post", this. _ base64encodeurl, false );
This. _ XMLHTTP. setRequestHeader ("Content-Type", "text/XML; charset = gb2312 ");
This. _ XMLHTTP. setRequestHeader ("soapaction", "http://tempuri.org/" + this. _ base64decodemethodname );
This. _ XMLHTTP. Send (data );
This. _ xmldoc. loadxml (this. _ XMLHTTP. responsetext );
VaR node = this.w.xmldoc.doc umentelement;
Return node. text;
} Catch (e ){
Alert ('method: decode64; error: '+ E. Message );
Return '';
}
}
// Replace unsupported characters in XML
Function encodexml (value ){
Value = value. Replace (/&/g, '& #38 ;');
Value = value. Replace (/</g, '& # x003e;'); // & gt;
Value = value. Replace (/>/g, '& lt ;');
Value = value. Replace (// G, '& # x00ae ;');
Value = value. Replace (// G, '& # x2122 ;');
Return value;
}