c# HttpWebRequest to amfphp/gateway.php

756 views Asked by At

Im trying to send a request to a amfphp/gateway.php and get back the responds in c# but I keeo getting this error:

Fatal error: Uncaught exception 'VerboseException' with message 'Malformed AMF message,                      connection may have dropped' in   /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFBaseDeserializer.php:210
Stack trace:
#0 [internal function]: amfErrorHandler(1024, 'Malformed AMF m...', '/usr/local/www/...',   210, Array)
#1 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFBaseDeserializer.php(210): trigger_error('Malformed AMF m...')
#2 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFBaseDeserializer.php(134): AMFBaseDeserializer->readHeader()
#3 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/app/Filters.php(38): AMFBaseDeserializer->deserialize(Object(AMFObject))
#4 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/app/Gateway.php(177): deserializationFilter(Object(AMFObject))
#5 /usr/local/www/realtime.fdim.dk/amfphp/gateway.php(155): Gateway->service()
#6 {main}
thrown in /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFBaseDeserializer.php on line 210

Here is my Code:

CookieContainer loginCookie = new CookieContainer();
private void button1_Click(object sender, EventArgs e)
    {
       //Login to realtime.fdim.dk
        String postData = "User.login "+"\n"+"username"+"\n"+"password";
        MessageBox.Show(postData);
        CookieContainer tempCookie = new CookieContainer();
        UTF8Encoding encodning = new UTF8Encoding();
        Byte[] bytedate = encodning.GetBytes(postdata);
        HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create("http://realtime.fdim.dk/amfphp/gateway.php");
        postRequest.Method = "POST";
        postRequest.KeepAlive = true;
        postRequest.CookieContainer = tempCookie;
        postRequest.ContentType = "application/x-amf";
        postRequest.Referer = "Referer: http://realtime.fdim.dk/application_v1.02.4.swf";
        postRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0";
        postRequest.ContentLength = bytedate.Length;
        Stream postReuestStream = postRequest.GetRequestStream();
        postReuestStream.Write(bytedate, 0, bytedate.Length);
        postReuestStream.Close();
        HttpWebResponse postResponse;
        postResponse = (HttpWebResponse)postRequest.GetResponse();
        tempCookie.Add(postResponse.Cookies);
        loginCookie = tempCookie;
        StreamReader postreqreader = new StreamReader(postResponse.GetResponseStream());
        String thePage = postreqreader.ReadToEnd();
        richTextBox1.Text = thePage;

so it seems that my postData is not encoded correctly But i dont know how to solve it..

Edit:

I have now change my Postdata to a hexString and then converts it to a byte[]:

String PostDataTest =  "00 03 00 00 00 01 00 0A 55 73 65 72 2E 6C 6F 67 69 6E 00 03 2F 31 32 00 00 00 2D 0A 00 00 00 02 02 00 18 6D 61 74 68 69 61 73 2E 73 2E 61 6E 64 65 72 73 65 6E 40 6A 70 2E 64 6B 02 00 0A 70 70 65 72 31 37 39 33 ";

Byte[] bytedate = ConvertHexStringToByteArray(PostDataTest);

bute now i get this error:

 Fatal error: Uncaught exception 'VerboseException' with message 'unpack(): Type d: not enough input, need 8, have 0' in /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFBaseDeserializer.php:334

Stack trace: #0 [internal function]: amfErrorHandler(2, 'unpack(): Type ...', '/usr/local/www/...', 334, Array) #1 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFBaseDeserializer.php(334): unpack('dflt', '') #2 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFDeserializer.php(276): AMFBaseDeserializer->readDouble() #3 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFDeserializer.php(163): AMFDeserializer->readData(0) #4 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFDeserializer.php(300): AMFDeserializer->readArray() #5 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFBaseDeserializer.php(226): AMFDeserializer->readData(10) #6 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFBaseDeserializer.php(134): AMFBaseDeserializer->readHeader() #7 /usr/local/www/realtime.fdim.dk/amfphp/core/amf/app/Filt in /usr/local/www/realtime.fdim.dk/amfphp/core/amf/io/AMFBaseDeserializer.php on line 334

0

There are 0 answers