【发布时间】:2010-03-21 14:02:55
【问题描述】:
我想使用 已发布的 GoogleDocs 文档 和 twitter 推文 作为 Silverlight 应用程序的数据源,但遇到了 clientaccesspolicy 问题。
我阅读了许多文章,例如this 和this,这些文章讲述了解决clientaccesspolicy 问题有多么困难。
所以我编写了这个 CURL 脚本 并将其放在我的 PHP 站点上,现在我可以将任何 GoogleDocs 文档和 twitter 提要的文本输入到我的 Silverlight 应用程序中:
<?php
$url = filter_input(INPUT_GET, 'url',FILTER_SANITIZE_STRING);
$validUrls[] = "http://docs.google.com";
$validUrls[] = "http://twitter.com/statuses/user_timeline";
if(beginsWithOneOfThese($url, $validUrls)) {
$user_agent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie");
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
echo curl_exec($ch);
} else
echo "invalid url";
function beginsWithOneOfThese($main, $prefixes) {
foreach($prefixes as $prefix) {
if(beginsWith($main, $prefix))
return true;
}
return false;
}
function beginsWith($main, $prefix) {
return strpos($main, $prefix) === 0;
}
?>
所以这让我想知道:
- 既然您只需要编写一个简单的代理脚本并通过它获取信息,为什么会有这么多讨论关于 URL 是否支持客户端访问策略?
- 为什么没有服务,例如像 URL 缩短服务,它提供这个功能?
- 拥有这样的脚本会有哪些安全隐患?
【问题讨论】:
标签: silverlight security clientaccesspolicy.xml