title: Download PDF file in Flex with HTTPService
body: <p>Hi<br>Someone know how to download a pdf file with HTTPService?<br>
  I do that</p>
  
  <pre><code>private function downloadPDF():void
  {
      var httpService:HTTPService = new HTTPService();
      httpService.url = "http://coenraets.org/flexandroid90/FlexAndroid90Minutes.pdf";
      httpService.addEventListener(ResultEvent.RESULT, result);
      httpService.addEventListener(FaultEvent.FAULT, fault);
      httpService.send();
  }
  
  private function fault(event:FaultEvent):void
  {
      trace("Error");
      trace("\t&gt; Code : "+event.fault.faultCode);
      trace("\t&gt; Description : "+event.fault.faultString);
      trace("\t&gt; Detail : "+event.fault.faultDetail);
  }
  
  private function result(event:ResultEvent):void
  {
      var pdfFile:File = new File(File.applicationStorageDirectory.nativePath + File.separator + "myPDF.pdf");
      var fileStream:FileStream = new FileStream();
      fileStream.open(pdfFile, FileMode.WRITE);
      fileStream.writeUTFBytes(event.result as String);
      fileStream.close();
  }
  </code></pre>
  
  <p>But I got an error </p>
  
  <blockquote>
    <p>Error<br>
    Code : Client.CouldNotDecode<br>
    Description : Error #1090: XML parser failure: element is malformed.<br>
    Detail : null</p>
  </blockquote>
  
  <p>With URLLoader it works fine</p>
  
  <pre><code>private function initPDF():void
  {
      loader = new downloadPDF();
      loader.dataFormat = URLLoaderDataFormat.BINARY;
      var request:URLRequest = new URLRequest("http://coenraets.org/flexandroid90/FlexAndroid90Minutes.pdf");
      configureListeners(loader);
      try {
          loader.load(request);
      } catch (error:Error) {
          trace("Unable to load requested URL.");
      }
  }
  
  private function configureListeners(dispatcher:EventDispatcher):void {
      dispatcher.addEventListener(Event.COMPLETE, completeHandler);
      dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
  }
  
  private function completeHandler(event:Event):void {
      var pdfFile:File = new File(File.applicationStorageDirectory.nativePath + File.separator + "myPDF.pdf");
      var fileStream:FileStream = new FileStream();
      fileStream.open(pdfFile, FileMode.WRITE);
      fileStream.writeBytes(loader.data);
      fileStream.close();
  }
  
  private function ioErrorHandler(event:IOErrorEvent):void {
      trace("ioErrorHandler: " + event);
  }
  </code></pre>