simonbengtsson / ajaxbridge
代理以绕过跨域策略
dev-master
2017-10-01 20:49 UTC
This package is not auto-updated.
Last update: 2024-09-24 00:57:31 UTC
README
AjaxBridge 的目的是充当代理以绕过跨域策略。它允许任何 JavaScript 向任何服务器发送任何请求并获得完整的响应,包括 cookie 头。
用法
此示例获取了推特主页的 html。唯一必需的选项是 url。
var options = {
url: 'https://twitter.com/',
method: 'GET',
headers: {
'User-Agent': 'AjaxBridge',
'Other-Header': 'Value'
},
content: ''
};
$.post('https://ajax-bridge.appspot.com', options, function (res) {
console.log(res); // See example response below
});
{
"protocol": "HTTP/1.1",
"status": 200,
"statusText": "OK",
"headers": {
"cache-control": "no-cache, no-store, must-revalidate, pre-check=0, post-check=0",
"content-security-policy-report-only": "default-src https:; connect-src https:; font-src https",
"content-type": "text/html;charset=utf-8",
"date": "Fri, 17 Oct 2014 18:16:10 UTC",
"expires": "Tue, 31 Mar 1981 05:00:00 GMT",
"last-modified": "Fri, 17 Oct 2014 18:16:10 GMT",
"ms": "S",
"pragma": "no-cache",
"server": "tsa_a",
"set-cookie": "guest_id=v1%3A141356977060427045; Domain=.twitter.com; Path=/; Expires=Sun, 16-Oct-2016 18:16:10 UTC",
"status": "200 OK",
"strict-transport-security": "max-age=631138519",
"x-connection-hash": "e43d6d1abaacfa287738a7a17f329665",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-transaction": "a1413ba660e67325",
"x-ua-compatible": "IE=edge,chrome=1",
"x-xss-protection": "1; mode=block",
"X-Google-Cache-Control": "remote-fetch",
"Via": "HTTP/1.1 GWA"
},
"content": "<!DOCTYPE html>\n<!--[if IE 8]><html class=\"lt-ie10 ie8\" lang=\"en data-scribe-reduced--containLogin or Sign up (...)"
}
托管和高级用法
通常您通过向 https://ajax-bridge.appspot.com 发送请求来使用 AjaxBridge。但是,有时在您自己的项目中安装它可能更合适,这可以通过 php composer.phar require simonbengtsson/ajaxbridge:dev-master
完成。托管您自己的 AjaxBridge 的最简单方法是将其中的所有文件上传到您选择的服务器。您可能需要调整 index.php 或 example.php。如果您想使用 Google App Engine,首先必须在 Google Cloud Console 中创建一个新的应用程序并相应地更改 app.yaml。
Google 云部署
./google-cloud-sdk/bin/gcloud app deploy app.yaml --project ajax-bridge