国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

WEB項目后端跨域請求

2024-05-04 21:54:35
字體:
來源:轉載
供稿:網友

   using System;

  using System.Collections.Generic;

  using System.IO;

  using System.Linq;

  using System.Net;

  using System.Text;

  using System.Web;

  using System.Web.SessionState;

  namespace GL

  {

  public class CrossDomainHandler:IHttpModule, IRequiresSessionState

  {

  ///

  /// 釋放內存

  ///

  public void Dispose()

  {

  }

  ///

  /// 開始請求

  ///

  ///

  public void Init(HttpApplication context)

  {

  //頁面開始請求時,綁定時間

  context.BeginRequest += new EventHandler(context_PreRequestHandlerExecute);

  }

  ///

  /// 請求處理

  ///

  ///

  ///

  void context_PreRequestHandlerExecute(object sender, EventArgs e)

  {

  HttpApplication app = (HttpApplication)sender;

  HttpContext context = 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 relativeAddr = context.Request.AppRelativeCurrentExecutionFilePath.Remove(0, 2);

  if (relativeAddr.StartsWith("Server"))

  {

  var url = string.Concat("http://localhost:89", relativeAddr.Substring(relativeAddr.IndexOf('/')));

  HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

  request.Method = "POST";

  request.ContentType = "application/x-www-form-urlencoded";

  var rs = request.GetRequestStream();

  var sb = new StringBuilder("a=a&");

  context.Request.Form.AllKeys.ToList().ForEach(name =>

  {

  sb.AppendFormat("{0}={1}&", name, context.Request.Form[name]);

  });

  var str = sb.ToString();

  if(str.Contains('&'))

  {

  str = str.Substring(0, str.Length - 1);

  }

  var sw = new StreamWriter(rs, Encoding.UTF8);

  sw.Write(sb.ToString());

  sw.Close();

  request.Timeout = 60 * 1000;

  var response = request.GetResponse() as HttpWebResponse;

  var ps = response.GetResponseStream();

  var reader = new StreamReader(ps, Encoding.UTF8);

  string html = reader.ReadToEnd();

  ps.Close();

  context.Response.Write(html);

  context.Response.End();

  }

  }

  }

  }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中牟县| 昭觉县| 铜川市| 惠州市| 灵山县| 汕头市| 抚松县| 鱼台县| 嘉义市| 宁化县| 沅陵县| 荆门市| 永修县| 喀喇沁旗| 东宁县| 汝南县| 隆化县| 盐边县| 乾安县| 孝昌县| 措勤县| 高安市| 宕昌县| 北票市| 洛阳市| 沂水县| 郓城县| 湖南省| 合阳县| 固阳县| 敦化市| 鄂尔多斯市| 沂源县| 闽清县| 涿州市| 潜山县| 炎陵县| 永定县| 原阳县| 永城市| 临江市|