无为清净楼资源网 Design By www.qnjia.com
最简单的调用方法:
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);
}
}
_http.send(this.data);
this.readyState = _http.readyState;
if(_http.readyState==4){
this.status = _http.status;
this.http = _http;
this.content = _http.responseBody;
}
return this;
}
_SmartHttp.prototype.getbinary=function(){
return this.content;
};
_SmartHttp.prototype.gettext=function(charset){
try{
return this.b2s(this.content,charset ? charset : this.charset);
}catch(ex){
this.msg = ex.description;
return "";
}
};
_SmartHttp.prototype.getjson=function(charset){
try{
var _json=null;
eval("_json=(" + this.gettext(charset) + ");");
return _json;
}catch(ex){
this.msg = ex.description;
return null;
}
};
_SmartHttp.prototype.getxml=function(charset){
try{
var _dom = new ActiveXObject("MSXML2.DOMDocument");
_dom.loadXML(this.gettext(charset).replace("&","&"));
return _dom;
}catch(ex){
this.msg = ex.description;
return null;
}
};
_SmartHttp.prototype.getobj = function (){
var b=null;
var httplist = ["MSXML2.serverXMLHttp.3.0","MSXML2.serverXMLHttp","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
for(var i = 0;i<=httplist.length -1;i++){
try{
b= new ActiveXObject(httplist[i]);
(function(o){
_SmartHttp.prototype.getobj = function(){return new ActiveXObject(o)};
})(httplist[i]);
return b;
}catch(ex){
//eval("this.msg = ex.description;");
}
}
return b;
};
_SmartHttp.prototype.getrnd = function (){return Math.random().toString().substr(2);};
_SmartHttp.prototype.b2s = function(bytSource, Cset){
var Objstream;
var byts;
Objstream =Server.CreateObject("ADODB.Stream");
Objstream.Type = 1;
Objstream.Mode = 3;
Objstream.Open();
Objstream.Write(bytSource);
Objstream.Position = 0;
Objstream.Type = 2;
Objstream.CharSet = Cset;
byts = Objstream.ReadText();
Objstream.Close();
Objstream = null;
return byts;
};
_SmartHttp.prototype.urlencode=function(str){ return encodeURIComponent(str);};
_SmartHttp.prototype.urldecode=function(str){ return decodeURIComponent(str);};
</script>
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);
}
}
_http.send(this.data);
this.readyState = _http.readyState;
if(_http.readyState==4){
this.status = _http.status;
this.http = _http;
this.content = _http.responseBody;
}
return this;
}
_SmartHttp.prototype.getbinary=function(){
return this.content;
};
_SmartHttp.prototype.gettext=function(charset){
try{
return this.b2s(this.content,charset ? charset : this.charset);
}catch(ex){
this.msg = ex.description;
return "";
}
};
_SmartHttp.prototype.getjson=function(charset){
try{
var _json=null;
eval("_json=(" + this.gettext(charset) + ");");
return _json;
}catch(ex){
this.msg = ex.description;
return null;
}
};
_SmartHttp.prototype.getxml=function(charset){
try{
var _dom = new ActiveXObject("MSXML2.DOMDocument");
_dom.loadXML(this.gettext(charset).replace("&","&"));
return _dom;
}catch(ex){
this.msg = ex.description;
return null;
}
};
_SmartHttp.prototype.getobj = function (){
var b=null;
var httplist = ["MSXML2.serverXMLHttp.3.0","MSXML2.serverXMLHttp","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
for(var i = 0;i<=httplist.length -1;i++){
try{
b= new ActiveXObject(httplist[i]);
(function(o){
_SmartHttp.prototype.getobj = function(){return new ActiveXObject(o)};
})(httplist[i]);
return b;
}catch(ex){
//eval("this.msg = ex.description;");
}
}
return b;
};
_SmartHttp.prototype.getrnd = function (){return Math.random().toString().substr(2);};
_SmartHttp.prototype.b2s = function(bytSource, Cset){
var Objstream;
var byts;
Objstream =Server.CreateObject("ADODB.Stream");
Objstream.Type = 1;
Objstream.Mode = 3;
Objstream.Open();
Objstream.Write(bytSource);
Objstream.Position = 0;
Objstream.Type = 2;
Objstream.CharSet = Cset;
byts = Objstream.ReadText();
Objstream.Close();
Objstream = null;
return byts;
};
_SmartHttp.prototype.urlencode=function(str){ return encodeURIComponent(str);};
_SmartHttp.prototype.urldecode=function(str){ return decodeURIComponent(str);};
</script>
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年11月13日
2024年11月13日
- 原神恰斯卡最强深渊阵容搭配推荐
- 盛惠决战双十一降临《坦克世界》
- 最终幻想1411月12日更新公告:7.05版本正式上线
- 守望先锋2经典6v6模式限时回归
- 康康《自由如风6N纯银SQCD》[WAV+CUE]
- 傅薇1991-迷雾中共舞[歌林][WAV+CUE]
- 王菲《菲故事6N纯银SQCD》WAV+CUE
- 群星.1996-宝丽金笑傲江湖精丫宝丽金】【WAV+CUE】
- 好日.2024-好日HoNi【风潮】【FLAC分轨】
- 陈文媛.2001-GRACEFUL【东方魅力】【WAV+CUE】
- 群星《音乐磁场02》国语经典名曲系列[低速原抓WAV+CUE][620M]
- 群星 -《2024好听新歌21》十倍音质 [WAV+分轨][991M]
- 群星 《2015香港高级视听展原音精选》SACD非卖品[WAV+CUE][1.2G]
- 英雄联盟双城之战第2季几点播出 双城之战第2季播出时间介绍
- 宝可梦大集结国服几点可以下载公测 大集结公测时间一览