使用 URLRequest + if 语句语法问题获取 POST
getting POST using URLRequest + if statement syntax issue
我正在尝试从 var url:String 中指定的地址获取回复,该地址为 0 或 1。如果回复为 1,则必须设置 currentState = CallFailed(如下所示)。客户端编译没有错误(使用 Adobe Flash Builder 4.6)并且似乎成功到达 var url:String,但似乎没有得到 response\and 或者我的 if 语句不正确。
动作脚本:
// check to see if block.php replies 0 or 1
var url:String = "https://domain.com/block.php?postid=" + calleeInput.text + "";
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
request.data = variables;
request.method = URLRequestMethod.POST;
navigateToURL(request);
if (request.data == 1)
{
// if reply is 1 then cancel the call
currentState = CallFailed;
return;
}
PHP:
当加载 block.php 时,PHP 将回显 0 或 1。它没有以任何格式编码,例如 JSON\AJAX.
您似乎需要来自服务器的数据。也许 URLLoader class 会更好?
var url:String = "https://domain.com/block.php?postid=" + calleeInput.text + "";
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
request.data = variables;
request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener( Event.COMPLETE,
function( e:Event ) : void
{
// your response data will be here
// you'll have to verify the format
trace( e.target.data );
}
)
loader.load( request );
在跟踪语句处打断点并检查e.target.data的内容,然后从那里开始
navigateToURL()
的目的是打开网络浏览器,如其文档中所述:
Opens or replaces a window in the application that contains the Flash Player container (usually a browser). In Adobe AIR, the function opens a URL in the default system web browser
为了执行请求(无需打开浏览器,仅通过 HTTP 通信),您应该使用 URLLoader
。
The URLLoader class downloads data from a URL as text, binary data, or URL-encoded variables.
相关说明:您的逻辑无效。对服务器的调用是异步的。需要等待response返回后才能推理结果。
URLLoader
class 调度大量事件,帮助您决定何时返回请求结果或是否存在问题。
我正在尝试从 var url:String 中指定的地址获取回复,该地址为 0 或 1。如果回复为 1,则必须设置 currentState = CallFailed(如下所示)。客户端编译没有错误(使用 Adobe Flash Builder 4.6)并且似乎成功到达 var url:String,但似乎没有得到 response\and 或者我的 if 语句不正确。
动作脚本:
// check to see if block.php replies 0 or 1
var url:String = "https://domain.com/block.php?postid=" + calleeInput.text + "";
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
request.data = variables;
request.method = URLRequestMethod.POST;
navigateToURL(request);
if (request.data == 1)
{
// if reply is 1 then cancel the call
currentState = CallFailed;
return;
}
PHP:
当加载 block.php 时,PHP 将回显 0 或 1。它没有以任何格式编码,例如 JSON\AJAX.
您似乎需要来自服务器的数据。也许 URLLoader class 会更好?
var url:String = "https://domain.com/block.php?postid=" + calleeInput.text + "";
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables();
request.data = variables;
request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener( Event.COMPLETE,
function( e:Event ) : void
{
// your response data will be here
// you'll have to verify the format
trace( e.target.data );
}
)
loader.load( request );
在跟踪语句处打断点并检查e.target.data的内容,然后从那里开始
navigateToURL()
的目的是打开网络浏览器,如其文档中所述:
Opens or replaces a window in the application that contains the Flash Player container (usually a browser). In Adobe AIR, the function opens a URL in the default system web browser
为了执行请求(无需打开浏览器,仅通过 HTTP 通信),您应该使用 URLLoader
。
The URLLoader class downloads data from a URL as text, binary data, or URL-encoded variables.
相关说明:您的逻辑无效。对服务器的调用是异步的。需要等待response返回后才能推理结果。
URLLoader
class 调度大量事件,帮助您决定何时返回请求结果或是否存在问题。