asp.net engine may be good, but it makes programmers think too stupid, will be self-righteous do a lot of automatic Encode and Decode, with the following examples:
If the client we post the following data,
But what you actually get is:
That is, the default invocation of the ASP.net engine provides us with the method:
byte[] Bytestopost = HttpLocalRequest.ContentEncoding.GetBytes (httpLocalRequest.Form.ToString ());
We are going to get a wrong result.
We must:
byte[] Bytestopost = readfully (httplocalrequest.inputstream);
Private byte[] readfully (Stream input)
{
byte[] buffer = new BYTE[16 * 1024];
using (MemoryStream ms = new MemoryStream ())
{
int read;
while (read = input. Read (buffer, 0, buffer.) Length)) > 0)
{
Ms. Write (buffer, 0, read);
}
Return Ms. ToArray ();
}
Author: cnblogs Loogn
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/