fra*_*ran 5 https post get xmlhttprequest
我能用XMLHttpRequest做Http请求(POST/GET).
我问如何使用像"https://www.gmail.com"这样的网址进行请求我正在尝试这样的事情,但状态代码为0
var http = new XMLHttpRequest();
    var url = "https://www.gmail.com";
    http.open("GET", url);
    http.onreadystatechange = function() {//Call a function when the state changes.
            if(http.readyState == 4 && http.status == 200) {
                    //alert(http.responseText);
                print("ok")
            }else{
                print("cannot connect")
                print("code:" + http.status)
                print(http.responseText)
            }
    }
    http.send(null);
我总是"无法连接""代码"0而没有任何反应
任何的想法?
这将失败有两个原因:
1)网址"https://www.gmail.com"实际上会尝试将您重定向到"https://mail.google.com/mail/",而后者会尝试将您重定向到登录页面.此重定向未列为错误
2)但更重要的是,除非该域支持CORS(http://www.html5rocks.com/en/tutorials/cors/),否则不能将XMLHttpRequests发送到其他域.GMail不支持CORS,因此该请求不起作用.
| 归档时间: | 
 | 
| 查看次数: | 19143 次 | 
| 最近记录: |