我正在编写一个应用程序,该应用程序从一个 URL 下载 XML 字符串,并将其POST
发送到另一个 URL(设置为处理传入的“XML
”字段) )。我已经完成了第一部分 - 它下载了 XML,我可以 alert()
它等等,但我无法弄清楚如何POST
数据到服务器。
function pull() {
var myLoader = new air.URLLoader();
var myRequest = new air.URLRequest('http://something/something.xml');
myLoader.addEventListener(air.Event.COMPLETE, pulled);
myLoader.load(myRequest);
}
function pulled(evt) {
if (evt.target.bytesTotal>0) {
// alerting shows the full string just fine
alert(evt.target.data);
var myLoader = new air.URLLoader();
var myRequest = new air.URLRequest('http://someplace/push.php');
myRequest.method = air.URLRequestMethod.POST;
// myVars = new air.URLVariables("xml="+evt.target.data); //
// alert(evt.target.data.toUpperCase());
myRequest.data = "xml="+evt.target.data; // myVars;
myLoader.dataFormat = air.URLLoaderDataFormat.TEXT;
myLoader.addEventListener(air.Event.COMPLETE, pushed);
myLoader.load(myRequest);
}
}
我让第二个服务器 PHP echo
xml
变量的内容,但我无法获取 XML 字符串的确切内容。我正在使用 myRequest.data
和/或 dataFormat
位做一些事情。
有人能解决这个问题吗?我知道这可能是一件简单的事情,但我现在束手无策。
这是我的第一个 AIR 应用程序。
另一个相关问题(或子问题)是......
alert(evt.target.data); // shows an alert box with the XML
alert(typeof evt.target.data); // shows String
alert(evt.target.data.toUpperCase()); // shows the xml converted to upper case
alert(encodeURI(evt.target.data)); // shows up blank.
alert(escape(evt.target.data)); // shows up blank.
为什么?
最佳答案
错误似乎是您将参数分配给“数据”的方式......使用 URLVariables。
var params:URLVariables = new URLVariables();
params.[name of parameter] = [value];
--- 就像您的示例中的 params.xml = (YOUR XML) ... 一样:
// uses the dynamic object to add the 'xml' property to 'params' at runtime.
params.xml = evt.target.data
然后将 request.data 更改为 request.data = params;
-- URLVariables 人员是动态的 - 因此您可以按照我上面的描述添加属性。
对于一个基本示例 - 比我这里的更完整:http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_2.html
关于php - 如何在 Adobe AIR 应用程序中通过 JavaScript 将 XML 数据发布到 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/931509/