Adobe-Runtime-Support icon indicating copy to clipboard operation
Adobe-Runtime-Support copied to clipboard

Is it possible to use URLRequestHeader with HTTPS

Open crooksy88 opened this issue 1 year ago • 4 comments

I'm currently using URLRequestHeader to upload mp3 data from an AIR desktop app using code similar to this...

appheader = new URLRequestHeader("Content-type", "application/octet-stream");
urlRequest = new URLRequest(http://www.blah.com/etc);
urlRequest.requestHeaders.push(appheader);
urlRequest.method = URLRequestMethod.POST;

I'm now having to update all my URL's to use HTTPS, but according to the AS3 docs, it looks like URLRequestHeader is only usable with HTTP calls.

[https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequestHeader.html]

Would anyone know how I can get around this?

Thanks in advance.

Mark

crooksy88 avatar Oct 10 '22 12:10 crooksy88

Have you tried it? I've just looked through the code, it gets a little convoluted and then goes into the various platform-specific implementations, but it looked to me as if headers would be used for any POST request..?

ajwfrost avatar Oct 12 '22 17:10 ajwfrost

Thanks for replying Andrew.

Yes I have tried it. My code works when using http. But when the url is changed to https no data is sent.

The domain ssl certificate is valid.

crooksy88 avatar Oct 12 '22 17:10 crooksy88

Interesting -> I couldn't see any code comments about this restriction. Can I check what platform you're using? We can take a look and see whether there's a good reason why headers are dropped for https..

ajwfrost avatar Oct 12 '22 19:10 ajwfrost

Currently testing with an AIR Windows app but the changes are also needed for MacOS, iOS and Android.

crooksy88 avatar Oct 12 '22 19:10 crooksy88

A quick update...

If I upload mp3 data to the https://URL using the Postman app this DOES work. So from that I am concluding the server and SSL certificate are valid and the issue does lie with AIR not being able to send the mp3 data via https.

The app does successfully send other text/xml formatted data via https to the same domain.

crooksy88 avatar Oct 14 '22 09:10 crooksy88

@crooksy88 we just tried looking at this but it seems to be working, at least on Windows judging from the results of the below:

		private function testHttpsHeaders() : void
		{
			var appheader : URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
			var urlRequest : URLRequest = new URLRequest("https://httpbin.org/anything");
			urlRequest.requestHeaders.push(appheader);
			urlRequest.method = URLRequestMethod.POST;
			urlRequest.data = new NeonMP4();
			var httpRes : URLStream = new URLStream();
			httpRes.addEventListener(Event.COMPLETE, function(e:Event):void {
				trace("Got result");
				var strOut : String = httpRes.readUTFBytes(httpRes.bytesAvailable);
				trace(strOut);
			});
			httpRes.load(urlRequest);
		}

where NeonMP4 is defined via:

		[Embed(source="neon.mp4", mimeType="application/octet-stream")]
		static public var NeonMP4:Class;

We get the response from the echo-server of:

Got result
{
  "args": {}, 
  "data": "data:application/octet-stream;base64,AAAAIGZ0eXBpc...then lots of base64 encoded data...", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, text/css, image/png, image/jpeg, image/gif;q=0.8, application/x-shockwave-flash, video/mp4;q=0.9, flv-application/octet-stream;q=0.8, video/x-flv;q=0.7, audio/mp4, application/futuresplash, */*;q=0.5, application/x-mpegURL", 
    "Accept-Encoding": "gzip,deflate", 
    "Content-Length": "1026103", 
    "Content-Type": "application/octet-stream", 
    "Host": "httpbin.org", 
    "Referer": "app:/AIRTestHarness.swf", 
    "User-Agent": "Mozilla/5.0 (Windows; U; en-US) AppleWebKit/533.19.4 (KHTML, like Gecko) AdobeAIR/50.0", 
    "X-Amzn-Trace-Id": "Root=1-6354753b-1599761429ec326723f4e27d", 
    "X-Flash-Version": "50,0,0,1"
  }, 
  "json": null, 
  "method": "POST", 
  "origin": "(my ip)", 
  "url": "https://httpbin.org/anything"
}

Are you able to check with this URL or see whether you're using a different method for the URL request?

ajwfrost avatar Oct 22 '22 23:10 ajwfrost

Hi Andrew, Thanks for looking into this for me. I really appreciate it.

Yes, using your code the mp3 does upload successfully over https to my server.

Having tested your code and mine as a standalone app and comparing this to my original app it seems that the issue could lie with me using a worker.swf to do the mp3 encoding and then uploading.

The mp3 is being encoded successfully but the worker.swf doesn’t seem to be able to upload this when using https.

When creating the worker I have tried both loading an embedded .swf and also loading the .swf from the same https domain as I am uploading to.

Perhaps it might have something to do with security?

crooksy88 avatar Oct 23 '22 11:10 crooksy88