dongzhang5006 2011-10-02 18:54
浏览 50
已采纳

Flash向php脚本发送2个变量,其中1个为xml

So this is probably a simple question, but for some reason, I'm having problems with it. I have no ideia why, but I suspect the fact that sending a xml with full "< something >" tags may cause the php to behave wrongly.

So all I need is to send (from a swf as3 client) a filename and a xml. The php will write a xml file with the required filename.

Everything should be okay with the php side, because I tried it using " $_GET " variables, but whenever I try using the flash client, It just doesent work, and the php log says that "the filename variable can't be empty". Whenever I try some static filename (not using GET or POST), it works.

Sooo... Can someone help me out with this one? Thanks.

EDIT: Code added.

var xmlURLReq:URLRequest = new URLRequest("www.url.com");
    var test:URLVariables = new URLVariables;
    test.filename = "01.xml";
    test.xmldata = xmltosave;
    xmlURLReq.data = teste;
    xmlURLReq.contentType = "text/xml";
    xmlURLReq.method = URLRequestMethod.POST;

    var xmlSendLoad:URLLoader = new URLLoader();
    xmlSendLoad.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
    xmlSendLoad.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
    xmlSendLoad.load(xmlURLReq);

    var alertBox:alertBoxClass = new alertBoxClass();
    alertBox.x = 0;
    alertBox.y = 200;

    function onComplete(evt:Event):void 
    { 
        try 
        {
            var xmlResponse = new XML(evt.target.data);
            alertBox.alertText.text = "Inserção de dados bem sucedida!";
            addChild(alertBox);
            removeEventListener(Event.COMPLETE, onComplete);
            removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
            writeXML()
        }
    }

I also tried Object and LoadVars classes instead of URLVariables, no luck so far.

EDIT: Might as well add the php code as well.

<?php
    $filename = "http://url.com/".$_POST["filename"];
    $xml = $_POST["xmldata"];
    $file = fopen($filename , "wb");
    fwrite($file, $xml);
    fclose($file);
?>
  • 写回答

1条回答 默认 最新

  • dougao9864 2011-10-02 20:56
    关注

    I see one possible problem in your code; You are setting the data to a URLVariables instance, but the contentType to "text/xml". It should be "application/x-www-form-urlencoded" when using URLVariables.

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html#contentType

    Hope that solves it!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题