我遇到了从HTTPS 网站向网站发送JSONP请求的问题。
我有一个(非本地)测试环境而不是https(有效证书),我可以运行所有这些跨站点"交叉协议"请求成功(有警告,但没有错误)。
Google Chrome Javascript控制台输出:
The page at https://my.test.environment/ ran insecure content from http://non.secure.site/service?jsonCallback=jsonp1331132928704
但是,在制作中,(在Google App Engine上,appspot子域名)Google Chrome会阻止所有等待用户确认的请求。
Google Chrome Javascript控制台输出(特别关注 [阻止] 文字):
[blocked] The page at https://production.appspot.com/ ran insecure content from http://non.secure.site/service?jsonCallback=jsonp1331132928704
我知道我所做的并不安全,但这项服务是由第三方提供的,到目前为止还没有SSL通信。我真的很困惑,因为我不知道为什么在测试环境中工作(有警告),而不是在appspot(Google App Engine)下工作。
我试图调查标题但没有成功。
测试环境标题:
Connection:Keep-Alive
Content-Encoding:gzip
Content-Language:es
Content-Length:2524
Content-Type:text/html;charset=utf-8
Date:Wed, 07 Mar 2012 15:48:30 GMT
Keep-Alive:timeout=15, max=100
Set-Cookie: cookie_info...
Vary:Accept-Encoding
APPSpot标题:
access-control-allow-credentials:false
access-control-allow-origin:*
cache-control:no-cache, must-revalidate
content-encoding:gzip
content-length:47890
content-type:text/html; charset=utf-8
date:Wed, 07 Mar 2012 14:52:02 GMT
expires:Fri, 01 Jan 1990 00:00:00 GMT
pragma:no-cache
server:Google Frontend
set-cookie: coookie_info....
status:200 OK
vary:Accept-Encoding
version:HTTP/1.1
我不知道为什么这会影响测试环境,谷歌浏览器在APPSpot上也会阻止相同的方法。
有什么想法吗?
答案 0 :(得分:1)
apache代理将代表您向端点发出请求。您甚至可以对服务(json,xml,图像,发布,发送,删除等)发出非jsonp请求,因为浏览器认为它正在向同一个域发出请求。
您的non.secure.site vhost文件将包含类似
的内容ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Allow from all
</Proxy>
ProxyPass /appspot https://production.appspot.com/
ProxyPassReverse /appspot https://production.appspot.com/
设置完成后,您只需将服务称为......
即可http://non.secure.site/appspot/service?jsonCallback=jsonp1331132928704
Google proxypass了解更多信息
https://serverfault.com/questions/429404/help-me-understand-how-to-use-proxypass
答案 1 :(得分:0)
如果您没有其他选择,但使用非安全的第三方API,您可以自己考虑MITM API。
创建一个服务器端脚本,该脚本只能通过SSL访问,并在您的代码和API之间充当代理或转发器。这样,您可以通过对数据进行自己的检查和验证来提高安全性,并且因为您将在SSL下提供服务,所以不会出现任何“混合内容”错误。
顺便说一下,我还没有对它进行测试,因此GAE提供的Google证书网站的行为总是有可能不同。希望我能提供帮助。
答案 2 :(得分:0)
我在http和https之间做同样的事情也遇到了同样的问题。这是一个跨域问题。
你需要的最重要的事情是你用来做curl的服务器端页面必须设置一些标题以允许http到https连接。这是...... ....
header("Access-Control-Allow-Origin: your https url");
header("Access-Control-Allow-Methods: POST, GET");
header("Access-Control-Max-Age: 1728000");
header("Access-Control-Allow-Headers: Content-Type, Connection, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
header("Connection: close");