C#后台跨域请求

通过C#后台发送请求来实现跨域访问(后台消耗会增大),源码如下:

   string URL = "www.xxx.com";
   public void sendPost(string urlArgs,HttpContext context)
   {
       //context.Request["args"]
       System.Net.WebClient wCient = new System.Net.WebClient();
       wCient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
       byte[] postData = System.Text.Encoding.ASCII.GetBytes("id=" + urlArgs);

       byte[] responseData = wCient.UploadData(URL, "POST", postData);

       string returnStr = System.Text.Encoding.UTF8.GetString(responseData);//返回接受的数据 

       context.Response.ContentType = "text/plain";
       context.Response.Write(returnStr);
   }

其他参考:

JSONP

JS跨域请求

跨域请求(XDR)简介

轻松利用Jquery实现Ajax跨域访问


你可能感兴趣的:(ASP.NET)