[英]Retrieving POST data in C# ASP.NET
I'm having troubles to make my program work correctly - here I explain : 我在使程序正常运行时遇到麻烦-在这里我解释:
myWebBrowser.Navigate(myUrl, "_blank", intarray, "");
我一方面拥有一个C#WinForms应用程序,该应用程序通过使用“ Navigate”方法启动IE的实例: myWebBrowser.Navigate(myUrl, "_blank", intarray, "");
, with intarray
defined like this : byte[] intarray = BitConverter.GetBytes(id);
,其intarray
定义如下: byte[] intarray = BitConverter.GetBytes(id);
. 。 On this side, it works. 在这一方面,它起作用。 On the other side, I have an ASP .NET WebForms application which has to retrieve this intarray
. 另一方面,我有一个ASP .NET WebForms应用程序,该应用程序必须检索此intarray
。 I've tried this. 我已经试过了
if (HttpContext.Current != null) { if (Session["Authenticated"] == null) { var current = HttpContext.Current; byte[] postdata = getpostdata(current); } } private byte[] getpostdata(HttpContext CurrentContext) { MemoryStream ms = new MemoryStream(); CurrentContext.Request.InputStream.CopyTo(ms); byte[] postdata = ms.ToArray(); return postdata; } // Convert a byte array to an Object public int ByteArrayToInt(byte[] arrBytes) { if (BitConverter.IsLittleEndian) Array.Reverse(arrBytes); int i = BitConverter.ToInt32(arrBytes, 0); return i; }
The problem seems to be in retrieving the Data in the getpostdata(HttpContext)
function... I get a byte array with length = 0 instead of the one which is sent with length = 4... Does anyone know how to make it work ? 问题似乎在于在getpostdata(HttpContext)
函数中检索数据...我得到的是长度为0的字节数组,而不是长度为4的字节数组...有人知道如何使它工作?
Yann 亚恩
var current = HttpContext.Current;
var sr = new StreamReader(Request.InputStream, Encoding.Default);
var postdata = sr.ReadToEnd();
above 以上
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.