我试图向amfphp / gateway.php发送请求并在c#中返回响应但我得到了这个错误:
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
这是我的代码:
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;
所以我的postData似乎没有正确编码 但我不知道如何解决它..
编辑:
我现在将Postdata更改为hexString,然后将其转换为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现在我收到了这个错误:
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
堆栈跟踪: #0 [内部函数]: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() #us /us//// / / / / / / / / / / / / / / / / / / /第334行