惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - Kriss Liu

绕开 CoreLab.MySql 验证 如何通过活动目录(ADSI)修改IIS6中的 Web 服务扩展 关于如何让页面同时下载多个文件的尝试 - Kriss Liu - 博客园 Remoting中的线程与网络通信内幕初探 Remoting多个信道(Chennel)的注册问题 基于强名称签名的代码访问保护及其改进 利用命名管道(Named Pipe)向Flash Player模拟Flash媒体文件 多样、互动的WinForm UI设计与开发思路(Flash、Html等) WinForm中设计时与DesignMode的区别 ServU插件设计 如何在C#中直接操作C++结构体 .NET中Flags枚举的使用 最近的计划。。VOS和DataSetBrowser。。 看完《仙剑奇侠传》前20集的一点牢骚。。 一套可嵌入或独立使用的翻页控件: WebPager(附源码) ASP.NET 2.0 中创建DataList子类控件时的一个错误 在.NET中使用DirectMusic 我与电脑的十年 关于 Windows Media DRM 0xC00D2840 错误
XMLDOM/XMLHTTP的跨域访问和页面代理
Kriss Liu · 2006-03-03 · via 博客园 - Kriss Liu

我们知道通过在页面中使用JavaScript调用微软的XMLDOM/XMLHTTP组件,可以方便的在页面中各种远程的资源,如网页和XML数据。不过由于IE默认安全级别的限制,我们并不能通过XMLDOM/XMLHTTP访问不同域的数据源。也就是说,www.siteA.com不能访问www.siteB.com里的页面。我们可以通过一个简单的本地页面代理来帮我们实现这个功能。新的流程将是: siteA.com/local.aspx (JavaScript)  -> siteA.com/agent.aspx?url=siteB.com/data.xml  -> siteB.com/data.xml

代码很简单,支持POST方式,但是GET方式的时候,URL里的其他参数目前都没有处理。

<%@ Page Language="C#" ClassName="PageAgent" ValidateRequest="false" %>

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>

<script type="text/C#" runat="server">
    
protected override void OnLoad(EventArgs e)
    
{
        Response.Clear();

        
string url = Request.QueryString["url"];
        
if (null == url || url.Trim().Length == 0)
        
{
            Response.End();
            
return;
        }


        
try
        
{
            WebRequest request 
= WebRequest.Create(url);
            request.Method 
= Request.RequestType;
            request.ContentType 
= Request.ContentType;

            
int reads = 0;
            
byte[] buffer = new byte[512];
            
            
if (Request.RequestType.Equals("POST", StringComparison.InvariantCultureIgnoreCase))
            
{
                
if (null != Request.Form) {
                    
using (Stream s = request.GetRequestStream())
                    
{
                        
while ((reads = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0)
                        
{
                            s.Write(buffer, 
0, reads);
                        }

                        s.Flush();
                    }

                }

            }


            WebResponse response 
= request.GetResponse();
            Response.ContentType 
= response.ContentType;
            
using (Stream s = response.GetResponseStream())
            
{
                
while ((reads = s.Read(buffer, 0, buffer.Length)) > 0)
                
{
                    Response.OutputStream.Write(buffer, 
0, reads);
                }

            }


            response.Close();
        }

        
catch
        
{
        }


        Response.End();
    }

</script>