Skip to main content
Inspiring
May 18, 2019
Question

Request to localhost with URLLoader not working

  • May 18, 2019
  • 1 reply
  • 321 views

Hello,

I'm trying to get a request to a localhost url to work but it doesn't seem to work with URLLoader though it does seem to work with the mx.rpc.http.HTTPServ class.

The following works

var httpServ:HTTPService = new HTTPService();

httpServ.method = "POST";

httpServ.contentType = "application/xml";

httpServ.url = "http://localhost:1813";

httpServ.send(requestData);

While this does not

var urlRequest:URLRequest = new URLRequest();

urlRequest.contentType = "application/xml";

urlRequest.url = "http://localhost:1813";

urlRequest.method = "POST";

var urlLoader:URLLoader = new URLLoader();

urlLoader.data = requestData;

urlLoader.load(urlRequest);

Can anyone tell me how to get the latter to work or why it's not working? It's giving me an IOErrorEvent. requestData is simply the request body in XML format

[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://localhost:1813" errorID=2032]

Thanks,
Kyle

This topic has been closed for replies.

1 reply

Inspiring
May 19, 2019

Try this one:

var urlRequest:URLRequest = new URLRequest(); 

urlRequest.url = "http://localhost:1813"; 

urlRequest.method = URLRequestMethod.POST;

var headers:Array = [

        new URLRequestHeader("contentType", "application/xml")];

urlRequest.requestHeaders = headers;

urlRequest.data = requestData;

var urlLoader:URLLoader = new URLLoader(); 

urlLoader.load(urlRequest); 

kamckngAuthor
Inspiring
May 19, 2019

Hi,

Thanks for the response.

I had actually tried that method first and when it didn't work, I saw the contentType property and attempted to use that. Neither method work unfortunately. I get the same error using URLRequestHeader as well

Kyle