HTTPS XMLHtt prequest未能获取正确的页面 [英] HTTPS XMLHttpRequest failing to retrieve correct page

查看:146
本文介绍了HTTPS XMLHtt prequest未能获取正确的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个网页的内容,但这个页面是使用HTTPS确保安全。我试图用XMLHtt prequest一个HTTP站点和成功,但这个页面不会返回页面的重定向,你必须登录。

I am trying to get content of a page, but this page is secured using https. I tried to use XMLHttpRequest with a http site and succeeded, but this page does return the redirect of the page where you have to log on.

下面是我的code我试图用

Below is my code I tried to use:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange=function() {
if (xhr.readyState==4 && xhr.status==200) {
document.getElementById("container").innerHTML = xhr.responseXML.body.innerHTML;
    };
};
xhr.open('POST', 'https://eu.battle.net/wow/en/vault/character/auction/alliance/', true);
xhr.withCredentials = true;

xhr.send();
document.getElementById("container").innerHTML = "loaded";

我试着设置requestheaders,包括饼干和验证和更改方法GET和POST,但没有什么区别。

I tried setting requestheaders, including cookies and authentication and changing the method to GET and POST but no difference.

谁能给我一个头了这个请求?

Can anyone give me a heads up on this request?

P.S。如果这是根本不可能,有没有办法用不同的方法来成功?

P.S. If this is not possible at all, is there any way to succeed using a different method?

推荐答案

您不能让AJAX请求跨域的,除非它返回一个访问控制允许来源头。从脚本中发起跨站点的HTTP请求都受到了著名的限制,很好理解的安全原因。对于使用XMLHtt prequest对象进行例如HTTP请求都受到同源策略。特别是,这意味着使用XMLHtt prequest一个Web应用程序只能作出HTTP请求它从,并没有对其他域加载域

You can't make AJAX requests cross-domain, unless it returns a Access-Control-Allow-Origin header. Cross-site HTTP requests initiated from within scripts have been subject to well-known restrictions, for well-understood security reasons. For example HTTP Requests made using the XMLHttpRequest object were subject to the same-origin policy. In particular, this meant that a web application using XMLHttpRequest could only make HTTP requests to the domain it was loaded from, and not to other domains.

更多信息: https://developer.mozilla.org/en-US /文档/ HTTP / Access_control_CORS

您可以绕过这个使用PHP代理:
http://blog.edwards-research.com/2012/10/cross-domain-ajax-a-simple-workaround/

You could bypass this using a PHP Proxy: http://blog.edwards-research.com/2012/10/cross-domain-ajax-a-simple-workaround/

这篇关于HTTPS XMLHtt prequest未能获取正确的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆