How to send AMF3 object via HttpClient Post Request

211 views Asked by At

I am working on a website which is old and uses AMF packages to send data to server. I need to send some text data to this website and save that data to this website. In other words I want to automate this website.

I found fluorinefx library but it is no longer supported by owner and there is no documentation on the internet about that. I tried to use fluorinefx's serialize class to serialize my dictionary data and send that to server with content-type header application/x-amf. But httpclient doesnt support AMF bytearrays.

When I tried to use fluorinefx's NetConnection class and use netConnection.Connect(url) method, if url starts with http:// there is no problem, but if url starts with https// it gives an URİFormat exception. Since the website I am working on uses https:// I cannot use this Connect method either.

So please help me, how can I prepare a correctly structured AMF object and send this with HttpClient. Or is there any other libraries which I can use for sending AMF packages.(I looked WebOrb and DotAmf too but theese are not working either)

Thanks.

1

There are 1 answers

1
cantgoogleme On
public static object SendAMF(string method, object[] arguments)
    {
        AMFMessage message = new AMFMessage(3);

        message.AddHeader(new AMFHeader("headerKey", false, "headerValue"));

        message.AddBody(new AMFBody(method, "/1", arguments));

        MemoryStream ms = new MemoryStream();
        AMFSerializer serializer = new AMFSerializer(ms);
        serializer.WriteMessage(message);
        serializer.Flush();
        serializer.Dispose();

        var request = (HttpWebRequest)WebRequest.Create($"{Endpoint}/Gateway.aspx?method={method}");

        byte[] data = Encoding.Default.GetBytes(Encoding.Default.GetString(ms.ToArray()));
        request.GetRequestStream().Write(data, 0, data.Length);

        try
        {
            var response = (HttpWebResponse)request.GetResponse();
            ms = new MemoryStream();
            response.GetResponseStream().CopyTo(ms);
            dynamic obj = DecodeAMF(ms.ToArray());
            ms.Dispose();
            response.Dispose();
            
            return obj;
        } 
        catch(Exception ex)
        {
            ms.Dispose();
            return "ERROR! " + ex.ToString();
        }
    }

public static dynamic DecodeAMF(byte[] body)
    {
        MemoryStream memoryStream = new MemoryStream(body);
        AMFDeserializer amfdeserializer = new AMFDeserializer(memoryStream);
        AMFMessage amfmessage = amfdeserializer.ReadAMFMessage();
        dynamic content = amfmessage.Bodies[0].Content;
        memoryStream.Dispose();
        amfdeserializer.Dispose();
        return content;
    }

`