当前位置: 网学 > 编程文档 > ASP > 正文

Ajax跨域代理访问网络资源的实现代码

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/16
pe.timeout=function(){
if(arguments.length>4){return this;}
for(var i =0;i<arguments.length;i++){
if(!isNaN(arguments[i])){
this.timeout[i] = parseInt(arguments[i]);
}
}
return this;
};

_SmartHttp.prototype.send=function(){
this.init();
var _http = this.getobj();
if(_http==null){return this;}
try{
_http.setTimeouts(this.timeout[0], this.timeout, this.timeout, this.timeout);
}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 = parseInt(_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.getheader=function(key){
if(key){
if(key.toUpperCase()=="SET-COOKIE"){
key = key.replace("-","\-");
var headers = this.http.getAllResponseHeaders();
var regexp = new RegExp("\n" + key + "\:(.+?)\r","ig");
var resstr = "";
while((res = regexp.exec(headers))!=null){
var val = res.trim();
resstr = resstr + val.substr(0,val.indexOf(";")) + "; "
}
if(resstr!=""){
resstr = resstr.substr(0,resstr.lastIndexOf(";"));
}
return resstr;
}else{
return this.http.getResponseHeader(key);
}
}else{return this.http.getAllResponseHeaders();}
};

_SmartHttp.prototype.getxml=function(charset){
try{
var _dom = new ActiveXObject("MSXML2.DOMDocument");
_dom.loadXML(this.gettext(charset));
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){ //ef bb bf,c0 fd
var Objstream,c1,c2,c3;
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.prot

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号