title: Flex 3 - how to support HTTP Authentication URLRequest?
body: <p>I have a Flex file upload script that uses URLRequest to upload files to a server. I want to add support for http authentication (password protected directories on the server), but I don't know how to implement this - I assume I need to extend the class somehow, but on how to I'm a little lost. </p>
  
  <p>I tried to modify the following (replacing HTTPService with URLRequest), but that didn't work.</p>
  
  <pre><code>private function authAndSend(service:HTTPService):void{        
     var encoder:Base64Encoder = new Base64Encoder();        
     encoder.encode("someusername:somepassword");        
     service.headers = {Authorization:"Basic " + encoder.toString()};
     service.send();
  }
  </code></pre>
  
  <p>I should point out that I'm not knowledgeable when it comes to ActionScript / Flex, although I have managed to successfully modify the upload script somewhat.</p>
  
  <p><strong>[Edit]</strong> - here is an update of my progress, based on the answer below, although I still cannot get this to work:</p>
  
  <p>Thank you for your assistance. I've tried to implement your code but I've not had any luck.</p>
  
  <p>The general behaviour I'm experiencing when dealing with HTTP authenticated locations is that with IE7 all is well but in Firefox when I attempt to upload a file to the server it displays an HTTP authentication prompt - which even if given the correct details, simply stalls the upload process.</p>
  
  <p>I believe the reason IE7 is ok is down to the the session / authentication information being shared by the browser and the Flash component - however, in Firefox this is not the case and I experience the above behaviour.</p>
  
  <p>Here is my updated upload function, incorporating your changes:</p>
  
  <pre><code>private function pergress():void 
  {
  if (fileCollection.length == 0) 
    {
    var urlString:String = "upload_process.php?folder="+folderId+"&amp;type="+uploadType+"&amp;feid="+formElementId+"&amp;filetotal="+fileTotal;
    if (ExternalInterface.available) 
      {
      ExternalInterface.call("uploadComplete", urlString);
      }
    }
  if (fileCollection.length &gt; 0) 
    {
    fileTotal++;
    var urlRequest:URLRequest = new URLRequest("upload_file.php?folder="+folderId+"&amp;type="+uploadType+"&amp;feid="+formElementId+"&amp;obfuscate="+obfuscateHash+"&amp;sessidpass="+sessionPass);
    urlRequest.method = URLRequestMethod.POST;
    urlRequest.data = new URLVariables("name=Bryn+Jones");
    var encoder:Base64Encoder = new Base64Encoder();
    encoder.encode("testuser:testpass");
    var credsHeader:URLRequestHeader = new URLRequestHeader("Authorization", "Basic " + encoder.toString());
    urlRequest.requestHeaders.push(credsHeader);
  
    file = FileReference(fileCollection.getItemAt(0));
    file.addEventListener(Event.COMPLETE, completeHandler);
    file.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus);
    file.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
    file.upload(urlRequest);
    }
  }
  </code></pre>
  
  <p>As stated above, I seem to be experiencing the same results with or without the amendments to my function. </p>
  
  <p>Can I ask also where the crossdomain.xml should be located - as I do not currently have one and am unsure where to place it.</p>