WebWorks AJAX跨域请求
我正在使用WebWorksSDK开发playbook应用程序。 我试图通过发送和接收数据来发出http请求(方法:post)。 我可以从服务器获取响应,但服务器无法获取$POST数据,当我尝试显示$_POST['apiKey']时,没有任何提示,我检查了我的代码100次,检查了我的config.xml的uri,找不到错误 TL;DR:无法发送但可以接收数据 我的PHP服务器代码:WebWorks AJAX跨域请求,ajax,blackberry,xmlhttprequest,blackberry-playbook,blackberry-webworks,Ajax,Blackberry,Xmlhttprequest,Blackberry Playbook,Blackberry Webworks,我正在使用WebWorksSDK开发playbook应用程序。 我试图通过发送和接收数据来发出http请求(方法:post)。 我可以从服务器获取响应,但服务器无法获取$POST数据,当我尝试显示$_POST['apiKey']时,没有任何提示,我检查了我的代码100次,检查了我的config.xml的uri,找不到错误 TL;DR:无法发送但可以接收数据 我的PHP服务器代码: echo "passed key is: ".$_POST["apiKey"]; // Nothing apears
echo "passed key is: ".$_POST["apiKey"]; // Nothing apears
echo "<br>";
if(md5($_SESSION['private_key'])===$_POST["apiKey"]){
}
else{
echo "Invalid API Key"; // Always getting this response on client app
exit();
}
?>
}
已解决: 使用POST方法时,应定义请求标头:
xdr.open("POST", "http://mydomain.com/index.php");
xdr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // with this line
xdr.send("apiKey="+key);
xdr.open("POST", "http://mydomain.com/index.php");
xdr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // with this line
xdr.send("apiKey="+key);
已解决:使用POST方法时,应定义请求标头:
xdr.open("POST", "http://mydomain.com/index.php");
xdr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // with this line
xdr.send("apiKey="+key);
xdr.open("POST", "http://mydomain.com/index.php");
xdr.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); // with this line
xdr.send("apiKey="+key);
你应该回答这个问题,这样它就不会被列为未回答的问题。