SmartHTTP 简单HttpRequest类(ASP)
发布时间:2023-08-02 10:30:32 所属栏目:Asp教程 来源:
导读:最简单的调用方法:
response.write SmartHttp("http://www.baidu.com/").send().gettext()
复杂调用
set myhttp = SmartHttp("http://www.baidu.com/s","GET")
myhttp.dataset.append "wd","smarthttp"
myht
response.write SmartHttp("http://www.baidu.com/").send().gettext()
复杂调用
set myhttp = SmartHttp("http://www.baidu.com/s","GET")
myhttp.dataset.append "wd","smarthttp"
myht
最简单的调用方法: response.write SmartHttp("http://www.baidu.com/").send().gettext() 复杂调用 set myhttp = SmartHttp("http://www.baidu.com/s","GET") myhttp.dataset.append "wd","smarthttp" myhttp.send() response.write myhttp.gettext("gbk") 复制代码 代码如下: <script language="jscript" runat="server"> 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.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;} if(this.data=="")this.data=null; this.url += ((this.url.indexOf("?")<0) ? "?" : "&") + "jornd=" + this.getrnd(); if(this.method=="GET" && this.data!=null) this.url += "&" + this.data; if(this.method=="POST") this.headers.push("Content-Type:application/x-www-form-urlencoded"); if(!this.charset || this.charset=="") this.charset = "gb2312"; }; _SmartHttp.prototype.header=function(headstr){ if(headstr.indexOf(":")>=0) this.headers.push(headstr); }; _SmartHttp.prototype.send=function(){ this.init(); var _http = this.getobj(); if(_http==null){return "";} try{_http.setTimeouts(10000,10000,10000,30000);}catch(ex){} _http.open(this.method,this.url,false); if(this.headers.length>0){ for(var i=0;i<this.headers.length;i++){ var Sindex = this.headers[i].indexOf(":"); var key = this.headers[i].substr(0,Sindex); var value = this.headers[i].substr(Sindex+1); _http.setRequestHeader(key,value); } (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐