欢迎来到天天文库
浏览记录
ID:63498574
大小:12.05 KB
页数:5页
时间:2021-10-12
《web项目后端跨域恳求_》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、web项目后端跨域恳求_usingsystem;usingsystem.collections.generic;usingsystem.io;usingsystem.linq;usingsystem.net;usingsystem.text;usingsystem.web;usingsystem.web.sessionstate;namespacegl{publicclasscrossdomainhandler:ihttpmodule,irequiressessionstate{//////释放内存///publicvoiddispose(){}////
2、//开头恳求//////publicvoidinit(httpapplicationcontext){//页面开头恳求时,绑定时间context.beginrequest+=neweventhandler(context_prerequesthandlerexecute);}//////恳求处理/////////voidcontext_prerequesthandlerexecute(objectsender,eventargse){httpapplicationapp=(httpapplication)sender;httpcontextcontext
3、=app.context;context.response.appendheader(charset,utf-8);context.response.appendheader(defaultcharset,utf-8);context.response.appendheader(content-type,text/html;charset=utf-8);varrelativeaddr=context.request.apprelativecurrentexecutionfilepath.remove(0,2);if(relativeaddr.starts
4、with(server)){varurl=string.concat(,relativeaddr.substring(relativeaddr.indexof('/')));httpwebrequestrequest=webrequest.create(url)ashttpwebrequest;request.method=post;request.contenttype=application/x--form-urlencoded;varrs=request.getrequeststream();varsb=newstringbuilder(a=a);
5、context.request.form.allkeys.tolist().foreach(name={sb.appendformat({0}={1},name,context.request.form[name]);});varstr=sb.tostring();if(str.contains('')){str=str.substring(0,str.length-1);}varsw=newstreamwriter(rs,encoding.utf8);sw.write(sb.tostring());sw.close();request.timeout=
6、60*1000;varresponse=request.getresponse()ashttpwebresponse;varps=response.getresponsestream();varreader=newstreamreader(ps,encoding.utf8);stringhtml=reader.readtoend();ps.close();context.response.write(html);context.response.end();}}}}更多信息请查看IT技术专栏...
此文档下载收益归作者所有