好吧,所以我是堆叠溢出的新手,但我有一个问题,我现在真的在绞尽脑汁。
基本上我有自己的HTTPS网址,我想发布到另一个HTTPS网址。但我不能。
我可以使用HTTP安全地发布到posttestserver.com,您可以看到here
这是我发帖时打电话的功能。
function POST(){
//var url = "http://posttestserver.com/post.php?dir=Titan";
var url = "cant say"
//var url = "http://httpbin.org/post"
var method = "POST";
if($("#zip").val() == "11111") url = "http://posttestserver.com/post.php?dir=Titan";
var postData = buildPost();
//alert(postData+"\n"+postData.getElementsByTagName("SourceIP")[0].childNodes[0].nodeValue)
var async = true;
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
var status = request.status; //200 for "200 OK"
var data = request.responseText; // Returned data, e.g., an HTML document.
if(request.readyState == 4){
if(url == "http://posttestserver.com/post.php?dir=Titan"){
alert("Status:"+status+"\nData:"+data+"\If You're seeing this error it means one of the fields has strange data in it. Please Contact an administrator to get this straightened out with this error. We apologize for the inconvenience.")
return 0
}
if(status == 200 || status == "200"){
alert("Thank You for using the site!")
window.location.href = "whew"
return 0
}
if(status != 200 && status != 0){
alert("Status:"+status+"\nData:"+data+"\ If You're seeing this error it means one of the fields has strange data in it. Please Contact an administrator to get this straightened out with this error. We apologize for the inconvenience.")
return 0
}
if(status < 100){
alert("An Unforseeable Error Occured?? Please Try Again.")
return 0
}
}
}
request.open(method, url, async);
request.setRequestHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Methods, Credentials");
request.setRequestHeader("Access-Control-Allow-Origin", "<target url>,<my url>");
request.setRequestHeader("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
request.setRequestHeader("Access-Control-Allow-Credentials", "true");
if(url != "http://posttestserver.com/post.php?dir=Titan")request.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
else{request.setRequestHeader("Content-Type", "application/xml;charset=UTF-8")}
// Or... request.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
// Or... whatever
request.send(postData);
}
基本上,我在尝试发布HTTPS服务器时不断获得的状态代码是0。
好的,这里有一些额外的信息。 Chrome控制台提供的信息比firefox控制台更多。
所以控制台说明了 XMLHttpRequest无法加载。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许原点访问。
所以我补充说: request.setRequestHeader(“Access-Control-Allow-Headers”,“Origin,X-Requested-With,Content-Type,Accept,Methods,Credentials”); request.setRequestHeader(“Access-Control-Allow-Origin”,“,”); request.setRequestHeader(“Access-Control-Allow-Methods”,“GET,PUT,POST,DELETE”); request.setRequestHeader(“Access-Control-Allow-Credentials”,“true”);
我仍然遇到同样的错误。