Lor*_*ark 5 php flash post http-post actionscript-3
经过一番研究,似乎这是一个非常受欢迎的问题.不幸的是,之前回答的问题都没有能够解决我面临的这个特殊问题.
首先,设置:
现在有了这样说,这就是守则.
请注意,我已将以下代码中的url更改为指向虚假Web服务器.我还将数据库连接信息更改为类似虚假.然而,结构的其余部分是正确的,包括文件夹结构和文件名:
Flash(Code.DataTransmitter):
public function SendData():void {
var myData:URLVariables = new URLVariables();
myData.update = "true";
myData.score_humans = MasterManager.gameManager.scoreHumans;
myData.score_creatures = MasterManager.gameManager.scoreCreatures;
var myRequest:URLRequest = new URLRequest("http://not-a-real-web-server.com/data/testgame.php");
myRequest.data = myData;
myRequest.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, OnSendDataComplete);
try {
loader.load(myRequest);
} catch (error:Error) {
trace ('Error: unable to load the document.');
}
}
public function OnSendDataComplete(e:Event):void {
}
Run Code Online (Sandbox Code Playgroud)
PHP:
<?php
if (isset($_POST['update'])) {
$dbhost = 'xxx.xxx.xxx.xxx';
$dbuser = 'bogususer';
$dbpass = 'boguspassword';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, 'test_game_table', 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$score_humans = intval( $_POST['score_humans'] );
$score_creatures = intval( $_POST['score_creatures'] );
if ($score_humans >= 0 && $score_creatures >= 0) { // Error-check: No negative values
$strquery = "update stats";
$strquery .= " set score_humans = score_humans + " . $score_humans;
$strquery .= ", score_creatures = score_creatures + " . score_creatures;
$strquery .= " where id = 1";
$strquery = $mysqli->real_escape_string($strquery); // Even though it should be clean, sanitize it anyways.
$mysqli->query($strquery);
echo "received=true";
}
}
echo "Hello there!";
?>
Run Code Online (Sandbox Code Playgroud)
现在,最后,问题.
这真的是一个简单的问题,可能不值得这么多序言,但我相信首先要获取所有信息并消除歧义,以减少在提出解决方案之前所需的问题数量.
更简洁地说,该请求似乎只能在通过Flash Professional发送时正常工作 - 当通过谷歌Chrome发送时,它会以某种身份失败.
我真的很感激解决这个问题的任何帮助.
先感谢您!
| 归档时间: |
|
| 查看次数: |
64 次 |
| 最近记录: |