3 Replies Latest reply on Dec 2, 2006 9:08 AM by thespark

    problem with sending xml to php with URLRequest

      Okeay if someone could tell me what is I am doing wrong? I get the following errors when I try to send xml file to a php and write it to xml file: Error #2044: Unhandled ioError:. text=Error #2032: Stream Error.

      And my code is following:

      Main app:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="LoadXML()" layout="absolute">
      <mx:Script source="VieraskirjaScripti.as"/>
      <mx:DataGrid x="10" y="10" valueCommit="sort(event)" id="mygrid" width="245" height="312" variableRowHeight="true">
      <mx:DataGridColumn headerText="Vieraskijan merkinnät" textAlign="center" fontFamily="Georgia" fontSize="15" fontWeight="bold" dataField="col1">
      <mx:Text fontFamily="Georgia" fontSize="12" fontWeight="normal" textAlign="right" text="{data.Nimi} kirjoitti:"/>
      <mx:Text fontFamily="Georgia" fontSize="12" fontWeight="normal" textAlign="right" text="{data.Viesti}"/>
      <mx:Image source="{ data.Kuva }"/>
      <mx:Button x="201" y="348" id="Uusi" click="LisaaUusi()" label="Button"/>
      <mx:Button x="298" y="348" label="save" click="SaveXML(); valmis.text = str"/>
      <mx:TextArea x="263" y="10" height="312" width="194" id="valmis"/>


      // ActionScript file
      import mx.collections.XMLListCollection;
      import mx.collections.Sort;
      import mx.collections.SortField;
      import flash.net.*;
      import flash.events.Event;
      private var str:String;
      private var myXML:XML = new XML();

      private function LoadXML():void{
      var XML_URL:String = "Vieraskirja.xml";
      var myXMLURL:URLRequest = new URLRequest(XML_URL);
      //myXMLURL.method = URLRequestMethod.POST;
      //myXMLURL.data = myXML
      var myLoader:URLLoader = new URLLoader(myXMLURL);
      myLoader.addEventListener("complete", xmlLoaded);

      private function xmlLoaded(evtObj:Event):void {
      var loader:URLLoader = URLLoader(evtObj.target);
      myXML = XML(loader.data);
      mygrid.dataProvider = myXML.elements('Merkinta');

      private function SaveXML():void{
      var PHP_URL:String = "Vieraskirja.PHP";
      var myPHPURL:URLRequest = new URLRequest(PHP_URL);
      myPHPURL.method = URLRequestMethod.POST;
      myPHPURL.contentType = "text/xml";//"application/xml";
      myPHPURL.data = myXML;
      var mySaver:URLLoader = new URLLoader(myPHPURL);
      mySaver.addEventListener("complete", phpSaved);
      private function phpSaved(evtObj:Event):void{
      var saver:URLLoader = URLLoader(evtObj.target);
      str = saver.data;
      private function LisaaUusi():void{
      var mychild:XML = <Merkinta>
      myXML = myXML.appendChild(mychild);
      mygrid.dataProvider = myXML.elements('Merkinta');

      private function sort(event:Event):void{
      if(!(mygrid.dataProvider == null)){
      var ac:XMLListCollection = XMLListCollection(mygrid.dataProvider);
      var sort:Sort = new Sort();
      sort.fields=[new SortField("Indeksi",true,true,true)];
      ac.sort = sort;

      nad my php file:

      $file = fopen("Vieraskirja.xml", "w+") or die("Can't open XML file");
      $xmlString = $HTTP_RAW_POST_DATA;
      if(!fwrite($file, $xmlString)){
      print "Error writing to XML-file";
      print $xmlString."\n";

      I just can't figure this out

      EDiT: my test Vieraskirja.xml looks like the following:

      <?xml version="1.0"?>