请原谅我,如果这已经得到回答/非常基本/问题措辞错误,我对此非常陌生并且在努力。
基本上我有生成XML的后端PHP,然后Flash构建器继承数据。我遇到的问题是了解Flash构建器如何通过HttpService向PHP发送参数,例如
这是它目前所解释的:
http://..../file.php?action=getitems
我希望Flash构建器发送的是
&class=fruit (<- the class would be dependant on what is selected from the drop down in the application)
整体创建此字符串
http://..../file.php?action=getitems&class=fruit
如果这是胡说八道,谢谢你并道歉。我正在使用Flash Builder 4。
答案 0 :(得分:1)
总的来说,我会使用push方法而不是传递变量,从而减少从中间被黑客入侵的可能性。
http呼叫的AS3代码:
public function someRequest() : void
{
var service : HTTPService = new HTTPService();
service.url = "http://localhost/getData.php";
service.useProxy = false;
service.method = "POST";
service.contentType = "application/xml"; // Pass XML data.
service.request = "<ID>somevalue</ID>"; // The XML data.
service.resultFormat = "xml"; // Recieve XML data.
service.addEventListener(ResultEvent.RESULT, createFields);
service.addEventListener(FaultEvent.FAULT, handleFault);
service.send();
}
private function createFields(event : ResultEvent) : void
{
var result : String = event.result.toString();
returnData = XML(result);
}
private function handleFault(event : FaultEvent) : void
{
var faultstring : String = event.fault.faultString;
Alert.show(faultstring);
}
正如您在中间看到的那样,有一个用于输入变量的XML空间。我使用这种方法将数据从PHP传递到AS3。
PHP是:
<?php
define("DATABASE_SERVER", "localhost");
define("DATABASE_USERNAME", "root");
define("DATABASE_PASSWORD", "**");
define("DATABASE_NAME", "dbName");
//connect to the database.
$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
mysql_select_db(DATABASE_NAME);
$Query = "SELECT * from data WHERE employeeID = '" . ($_POST['ID']) . "'";
$Result = mysql_query($Query);
$Return = "<data>";
while ($User = mysql_fetch_object($Result))
{
$Return .= "<user><userid>" . $User->userid . "</userid><username>" . $User->username . "</username><emailaddress>" . $User->emailaddress . "</emailaddress></user>";
}
$Return .= "</data>";
mysql_free_result($Result);
print ($Return)
?>
希望能帮到你。
答案 1 :(得分:1)
这在Flex中实际上相当简单......
var service : HTTPService = new HTTPService();
service.url = "http://localhost/getData.php";
service.method = "POST";
var parameters:Object = new Object();
parameters["action"] = "getitems";
parameters["class"] = "fruit";
service.send(parameters);
......完成!
答案 2 :(得分:1)
我通常通过[POST]代替[GET]
来处理这个问题在你的动作函数中:
private function sendRequest():void {
var obj:Object = new Object();
obj.action="getitems";
obj.class="fruit";
myService.send(obj);
您的httpService
<s:HTTPService id='myService' url='urlToYourPHP' method='POST' result='yourResultHandler' fault='yourFaultHandler' resultFormat='XML'/>
正如powelljf3所说,POST比GET更安全,尽管它仍然可以获得。