COMMUNITY

openfl.net.URLStream is not posting the message

Hello,

In flash, we were using the URLStream to send the Post Messages and it was working perfectly.
I have converted the code to Haxe targeting html5.

And I see the Post message in the html5 but this message not received by the server.

Working Example with Postman

not working example using openfl URLStream

our code is

    private function request(x : ByteArray) : Void
    {
        
        m_stream = new URLStream();
        m_stream.addEventListener(Event.COMPLETE, onComplete);
        m_stream.addEventListener(IOErrorEvent.IO_ERROR, onFatalError);
        m_stream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onFatalError);
        m_stream.addEventListener(HTTPStatusEvent.HTTP_STATUS, onProgress);
        m_stream.addEventListener(ProgressEvent.PROGRESS, onProgress);
        m_stream.addEventListener(Event.OPEN, onOpen);
		
		
        
	var theBytes =  com.hurlant.util.ByteArray.fromBytes(Bytes.ofData(x));
	var body : String = Base64.encodeByteArray(x);
	 trace(body);
        //var body : String = Base64.encodeByteArray(x);
        
        var request : URLRequest = new URLRequest();
        request.url = m_url;
        request.method = URLRequestMethod.POST;
        request.contentType = "application/json";
        request.data = body;
		var header = new URLRequestHeader("Access-Control-Allow-Origin","*");
		request.requestHeaders.concat([header]);
        
        m_stream.load(request);
    }

We tried to send the request using HTTP and it works but it’s sending two requests because of the referrer-policy and it’s doing some problem with our server

	      req = new Http( m_url);
			
		req.onData = onComplete;
		req.onError = onFatalError;
		req.onStatus = onProgress;
		req.onBytes = onBytes;
		req.setPostData(body);
		req.request(true);

Also using the Http is generating some errors like

HttpJs.hx:73 Uncaught TypeError: _gthis.onStatus is not a function at 

XMLHttpRequest.onreadystatechange (HttpJs.hx:73)

||onreadystatechange|@|HttpJs.hx:73|
| --- | --- | --- | --- |
||XMLHttpRequest.send (async)|||
||XHR.send|@|index.html?v=18980&e…"sandbox": true}:68|
||request|@|HttpJs.hx:133|
||request|@|HttpSession.hx:121|
||processData|@|HttpSession.hx:314|
||onComplete|@|HttpSession.hx:267|
||success|@|HttpBase.hx:236|
||onreadystatechange|@|HttpJs.hx:76|

Thanks in advance

Any Help for this

Maybe you can try to publish on OpenFL forum: https://community.openfl.org/