好吧我试图将某些数据发布到某个网站以获取g,但javascript似乎并不像我那样:(。 要执行请求,我会这样做:
var xmlhttp;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST","http://(removed)/forums/en/shoutbox_comet.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=utf-8");
xmlhttp.setRequestHeader("X-Request","JSON");
xmlhttp.setRequestHeader("Cookie",document.cookie);
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4)
alert(xmlhttp.responseText);
}
var channels = ['english_486', 'english_0', 'english_459','english_293','english_1310','english_292','english_459','english_293','english_970'];
var channel = channels[Math.floor(Math.random() * channels.length)];
var data = "channel="+channel+"&action=publish&type=message&data=HelloWorld";
xmlhttp.send(data);
发送此信息:
OPTIONS http://(removed)/forums/en/shoutbox_comet.php HTTP/1.1
Host: (removed)
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://(removed)
Access-Control-Request-Method: POST
Access-Control-Request-Headers: x-request
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
我该如何解决这个问题? 我希望它发送:
POST http://(removed)/forums/en/shoutbox_comet.php HTTP/1.1
Host: (removed)
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
X-Request: JSON
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Referer: http://(removed)/forums/en/shoutbox_comet_standalone.php?f=293&style=popout
Content-Length: 55
Cookie: (removed)
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
channel=english_293&action=publish&type=message&data=HelloWorld
答案 0 :(得分:1)
您正在向其他域发出请求。这是浏览器的安全问题。输入CORS。浏览器在POST之前发送一个OPTIONS请求(有时称为“预检”请求),以确定服务器是否可以响应它。
您必须确保服务器正确地响应这些请求。