actionscript-3apache-flexamf

change protocol of endpoint in AMFChannel, how to fix it?


I am working on Flex and I find that when I give uri(https://jsonplaceholder.typicode.com/posts/1) to AMFChannel which content 'HTTPS' protocal but calculateEndpoint() method of Channel class change protocol from "HTTPS" to "HTTP".

I also made simple project to demonstrate how endpoint gets changed by AMFChannel.

<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script><![CDATA[
    import mx.controls.Alert;
    import mx.messaging.ChannelSet;
    import mx.messaging.channels.AMFChannel;
    import mx.rpc.AbstractOperation;
    import mx.rpc.remoting.mxml.RemoteObject;


    private function button1_clickHandler(event:MouseEvent):void
    {
        var amfChannelWeb:AMFChannel = new AMFChannel("amfChannel", txtInput.text);

        var remoteObj:RemoteObject = new RemoteObject();
        remoteObj.showBusyCursor = true;
        remoteObj.requestTimeout = 0;

        var channelSet = new ChannelSet();
        channelSet.channels = [amfChannelWeb];


        remoteObj.destination = "amfphp";
        remoteObj.channelSet = channelSet;


        var op:AbstractOperation = remoteObj.getOperation("testAmfData");
        op.send();
        op.addEventListener("result", resultHandler);
        op.addEventListener("fault", resultFaultHandler);
        lblEndpoint.text = amfChannelWeb.endpoint;
    }

    private function resultHandler(e:Event):void
    {
        lblChannelError.text = e.toString();
    }

    private function resultFaultHandler(e:Event):void
    {
        lblChannelError.text = e.toString();
    }
    ]]></fx:Script>

<s:VGroup width="100%">

    <s:TextInput width="80%" id="txtInput" text="https://jsonplaceholder.typicode.com/posts/1"/>
    <s:Button click="button1_clickHandler(event)" label="Click"/>
    <s:Label id="lblEndpoint"/>
    <s:Label id="lblChannelError"/>

</s:VGroup>

Is this issue or am I doing somthing wrong??


Solution

  • Instead of AMFChannel use SecureAMFChannel as below

     var amfChannelWeb:SecureAMFChannel = new SecureAMFChannel("amfChannel", txtInput.text);