2 Replies Latest reply on Feb 27, 2007 9:20 PM by jpwrunyan

    HTTPService vs. URLRequest

    SeanFlash
      Hi all,

      I'm looking to fetch data from another server and have a few specific requirements...
      1) The request path is provided by the user (host remains the same, however).
      2) I need to add a few http headers.
      3) The response data is text (not necessarily xml).

      Is HTTPService or URLRequest the appropriate approach? I've begun working with URLRequest, but bumping into the problem that I get the following error on what I believe are non-200 responses:

      Error caught: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://www.foo.com//"

      The code I've put together thus far is roughly:

      var request:URLRequest = new URLRequest(host + requestPath);
      request.method = method;

      // Set headers.
      var headers:Array = request.requestHeaders;
      headers.push(new URLRequestHeader("x-foo", "foo"));
      headers.push(new URLRequestHeader("x-bar", "bar"));

      try {
      var loader:URLLoader = new URLLoader();
      loader.addEventListener(Event.COMPLETE, done);
      loader.addEventListener(IOErrorEvent.IO_ERROR, catchIOError);
      loader.load(request);
      } catch (error:Error) {
      log("Unable to load requested document.");
      log(error.toString());
      }

      Any help is very much appreciated!
      Thanks!
      Sean
        • 1. Re: HTTPService vs. URLRequest
          theLoggerGuy Level 1
          I'm only a novice, but I can't figure out how to return XML data in E4X formal using URLRequest. This is easy to do using HTTPService. That's the only difference I've found so far.

          On another note, looking at what you posted, your URL has two forward slashes on the end. Perhaps it's just a badly formatted string you are passing into "request".
          • 2. Re: HTTPService vs. URLRequest
            jpwrunyan Level 1
            URLLoader can only load data on the same domain as the .swf. HTTPService can be used to access data from another domain. Check the API.

            Here's the key information from URL loader:
            "The value you pass for the url parameter must, by default, be in exactly the same domain. For example, a SWF file at www.adobe.com can load data only from sources that are also at www.adobe.com. To load data from a different domain, place a cross-domain policy file on the server hosting the SWF file."