smart.asp
復(fù)制代碼 代碼如下:
<script language="jscript" runat="server">
/*
在VBS里面的調(diào)用方法
dim myhttp
set myhttp = SmartHttp(url,method,data); //三個參數(shù)均可選
屬性:
url:String,請求的URL地址
method:String,請求的方法
data:String,請求的數(shù)據(jù)
charset:String,請求的URL返回數(shù)據(jù)的編碼
status:Int,請求返回的狀態(tài)碼
readyState:Int,同HTTP請求的當(dāng)前通訊狀態(tài),1、2、3、4
dataset:Object,請求的數(shù)據(jù),如果增加了,會將這部分?jǐn)?shù)據(jù)附加到data屬性
dataset屬性:
charset:String,發(fā)送數(shù)據(jù)的編碼
dataset方法:
append(key,value,noencode):添加數(shù)據(jù)
remove(key):移除某個數(shù)據(jù)項
isexists(key):判斷某個數(shù)據(jù)項是不是存在
clear:清除所有數(shù)據(jù)項
方法:
header(headstr):設(shè)置請求頭,項和值之間用:分開
timeout(t1,t2,t3,t4):設(shè)置超時時間
send():發(fā)送請求
getbinary:獲取服務(wù)器返回的二進制數(shù)據(jù)
gettext(charset):獲取指定編碼的文本
getjson(charset):獲取指定編碼的json數(shù)據(jù)
getheader(key):獲取服務(wù)器返回的響應(yīng)頭
getxml(charset):獲取指定編碼的xml數(shù)據(jù)
*/
function SmartHttp(url,method,data){
return new _SmartHttp(url,method,data);
}
function _SmartHttp(url,method,data){
if(typeof method=="undefined") method="GET";
if(typeof data=="undefined") data="";
method = method.toUpperCase();
method = method!="POST" ? "GET" : "POST";
this.timeout=[10000,10000,10000,10000];
this.method = method;
this.url=url;
this.data=data;
this.charset="gb2312";
this.http=null;
this.headers=[];
this.status=0;
this.readyState=0;
this.content=null;
this.msg="";
this.dataset={
charset:"gb2312",
data:[],
append:function(key,value,noencode){
var fn=null;
if(this.charset.toLowerCase()=="utf-8"){fn = encodeURIComponent;}else{fn = escape;}
if(noencode==true){fn=function(_str){return _str;}}
this.data.push({"key":fn(key),"value":fn(value)});
},
remove:function(key){
if(this.data.length<=0) return false;
var _data=[];
for(var i=0;i<this.data.length;i++){
if(this.data[i].key!=key){
_data.push(this.data[i]);
}
}
this.data = _data;
},
isexists:function(key){
if(this.data.length<=0) return false;
for(var i=0;i<this.data.length;i++){
if(this.data[i].key==key){
return true;
}
}
return false;
},
clear:function(){
this.dataset.data=[];
}
};
}
_SmartHttp.prototype.init=function(){
var datasetstr="";
if(this.dataset.data.length>0){
for(var i=0;i<this.dataset.data.length;i++){
datasetstr += this.dataset.data[i].key + "=" + this.dataset.data[i].value + "&";
}
}
if(datasetstr!="") datasetstr = datasetstr.substr(0,datasetstr.length-1);
if(this.data==""){this.data = datasetstr;}else{if(datasetstr!="")this.data+= "&" + datasetstr;}