欢迎来到天天文库
浏览记录
ID:63498572
大小:12.11 KB
页数:5页
时间:2021-10-12
《WEB项目后端跨域恳求__1》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、WEB项目后端跨域恳求_usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Net;usingSystem.Text;usingSystem.Web;usingSystem.Web.SessionState;namespaceGL{publicclassCrossDomainHandler:IHttpModule,IRequiresSessionState{//////释放内
2、存///publicvoidDispose(){}//////开头恳求//////publicvoidInit(HttpApplicationcontext){//页面开头恳求时,绑定时间context.BeginRequest+=newEventHandler(context_PreRequestHandlerExecute);}//////恳求处理/////////voidcontext_PreRequestHandlerExecute(objectsender,EventArgse){Htt
3、pApplicationapp=(HttpApplication)sender;HttpContextcontext=app.Context;context.Response.AppendHeader("charset","utf-8");context.Response.AppendHeader("defaultCharset","utf-8");context.Response.AppendHeader("Content-Type","text/html;charset=utf-8");var
4、relativeAddr=context.Request.AppRelativeCurrentExecutionFilePath.Remove(0,2);if(relativeAddr.StartsWith("Server")){varurl=string.Concat("",relativeAddr.Substring(relativeAddr.IndexOf('/')));HttpWebRequestrequest=WebRequest.Create(url)asHttpWebRequest;
5、request.Method="POST";request.ContentType="application/x--form-urlencoded";varrs=request.GetRequestStream();varsb=newStringBuilder("a=a");context.Request.Form.AllKeys.ToList().ForEach(name={sb.AppendFormat("{0}={1}",name,context.Request.Form[name]);})
6、;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=60*1000;varresponse=request.GetResponse()asHttpWebResponse;varps=response.GetRespo
7、nseStream();varreader=newStreamReader(ps,Encoding.UTF8);stringhtml=reader.ReadToEnd();ps.Close();context.Response.Write(html);context.Response.End();}}}}更多信息请查看IT技术专栏...
此文档下载收益归作者所有