권한이 없다고 보고되는 Ajax 교차 도메인 액세스 문제를 해결합니다. 도움이 필요한 친구들이 참고할 수 있습니다. smart.asp
다음과 같이 코드 코드를 복사합니다.
<스크립트 언어=jscript runat=서버>
/*
VBS의 호출 방법
희미한 내http
set myhttp = SmartHttp(url,method,data); //세 가지 매개 변수는 모두 선택 사항입니다.
재산:
url: 문자열, 요청된 URL 주소
메소드: 문자열, 요청된 메소드
data: 문자열, 요청된 데이터
charset: 문자열, 요청된 URL에서 반환된 데이터의 인코딩
status: Int, 요청에 의해 반환된 상태 코드
ReadyState: Int, HTTP 요청과의 현재 통신 상태, 1, 2, 3, 4
데이터세트: 요청된 데이터인 개체입니다. 추가되면 데이터의 이 부분이 데이터 속성에 추가됩니다.
데이터 세트 속성:
charset: 문자열, 전송된 데이터의 인코딩
데이터 세트 방법:
추가(키,값,noencode): 데이터 추가
제거(키): 데이터 항목 제거
isexists(key): 데이터 항목이 존재하는지 확인
명확한: 모든 데이터 항목을 지웁니다.
방법:
header(headstr): 요청 헤더를 설정하고 다음을 사용하여 항목과 값을 구분합니다.
timeout(t1,t2,t3,t4): 타임아웃 시간을 설정합니다.
send(): 요청 보내기
getbinary: 서버에서 반환된 바이너리 데이터를 가져옵니다.
gettext(charset): 지정된 인코딩의 텍스트를 가져옵니다.
getjson(charset): 지정된 인코딩의 json 데이터를 가져옵니다.
getheader(key): 서버가 반환한 응답 헤더를 가져옵니다.
getxml(charset): 지정된 인코딩의 xml 데이터를 가져옵니다.
*/
함수 SmartHttp(url,메서드,데이터){
새로운 _SmartHttp(url,method,data)를 반환합니다.
}
함수 _SmartHttp(url,메서드,데이터){
if(방법 유형==정의되지 않음) 방법=GET;
if(데이터 유형==정의되지 않음) 데이터=;
메소드 = 메소드.toUpperCase();
메소드 = 메소드!=POST GET : POST;
this.timeout=[10000,10000,10000,10000];
this.method = 방법;
this.url=url;
this.data=데이터;
this.charset=gb2312;
this.http=null;
this.headers=[];
this.status=0;
this.readyState=0;
this.content=null;
this.msg=;
this.dataset={
문자셋:gb2312,
데이터:[],
추가:함수(키,값,인코드 없음){
var fn=널;
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)});
},
제거:함수(키){
if(this.data.length<=0) return false;
var _data=[];
for(var i=0;i<this.data.length;i++){
if(this.data[i].key!=키){
_data.push(this.data[i]);
}
}
this.data = _data;
},
isexists:함수(키){
if(this.data.length<=0) return false;
for(var i=0;i<this.data.length;i++){
if(this.data[i].key==키){
사실을 반환;
}
}
거짓을 반환;
},
클리어:함수(){
this.dataset.data=[];
}
};
}
_SmartHttp.prototype.init=function(){
var 데이터세트str=;
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 = 데이터세트str;}else{if(datasetstr!=)this.data+= & + 데이터세트str;}
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.timeout=function(){
if(arguments.length>4){return this;}
for(var i =0;i<arguments.length;i++){
if(!isNaN(인수[i])){
this.timeout[i] = parsInt(arguments[i]);
}
}
이거 돌려줘;
};
_SmartHttp.prototype.send=function(){
this.init();
var _http = this.getobj();
if(_http==null){이것을 반환;}
노력하다{
_http.setTimeouts(this.timeout[0], this.timeout[1], this.timeout[2], this.timeout[3]);
}잡기(예){}
_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;
}
이거 돌려줘;
}
_SmartHttp.prototype.getbinary=function(){
this.content를 반환합니다.
};
_SmartHttp.prototype.gettext=function(charset){
노력하다{
return this.b2s(this.content,charset ? charset : this.charset);
}잡다(예){
this.msg = ex.설명;
반품 ;
}
};
_SmartHttp.prototype.getjson=function(charset){
노력하다{
var _json=null;
eval(_json=( + this.gettext(charset) + ););
_json을 반환합니다.
}잡다(예){
this.msg = ex.설명;
null을 반환;
}
};
_SmartHttp.prototype.getheader=함수(키){
if(키){
if(key.toUpperCase()==SET-COOKIE){
키 = key.replace(-,/-);
var headers = this.http.getAllResponseHeaders();
var regexp = new RegExp(/n + 키 + /:(.+?)/r,ig);
var resstr = ;
while((res = regexp.exec(headers))!=null){
var val = res[1].trim();
resstr = resstr + val.substr(0,val.indexOf(;)) + ;
}
if(ressstr!=){
resstr = resstr.substr(0,resstr.lastIndexOf(;));
}
resstr을 반환;
}또 다른{
return this.http.getResponseHeader(key);
}
}else{return this.http.getAllResponseHeaders();}
};
_SmartHttp.prototype.getxml=function(charset){
노력하다{
var _dom = new ActiveXObject(MSXML2.DOMDocument);
_dom.loadXML(this.gettext(charset));
_dom을 반환합니다.
}잡다(예){
this.msg = ex.설명;
null을 반환;
}
};
_SmartHttp.prototype.getobj = 함수(){
var b=널;
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++){
노력하다{
b= new ActiveXObject(httplist[i]);
(함수(o){
_SmartHttp.prototype.getobj = function(){return new ActiveXObject(o)};
})(httplist[i]);
b를 반환;
}잡다(예){
eval(this.msg = ex.description;);
}
}
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 바이트;
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;
바이트 = Objstream.ReadText();
Objstream.Close();
Objstream = null;
바이트를 반환합니다.
};
_SmartHttp.prototype.urlencode=function(str){ return encodeURIComponent(str);};
_SmartHttp.prototype.urldecode=function(str){ return decodeURIComponent(str);};
String.prototype.trim = function(){return this.replace(/(^(/s+)|(/s+)$)/igm,);};
</script>
사용 코드:
다음과 같이 코드 코드를 복사합니다.
<!--#포함 파일=smart.asp-->
<%
Response.charset=utf-8
희미한 URL, 메서드, 데이터, 문자 집합
url =Request.Form(대상 URL)
메소드 =Request.Form(메소드)
데이터 =요청.양식(데이터)
charset = Request.Form(문자 집합)
charset =이면 charset = GB2312
response.Write SmartHttp(url,method,data).send().gettext(charset)
myhttp = 아무것도 설정하지 않음
%>