下面是一个用JAVA写的在ASP页面接收XML数据的程序,请问如何把它用C#写出来啊?非常感谢!
ServletInputStream sin = request.getInputStream();
byte[] buf = new byte[51200];
int index = 0;
while (true) {
   int ch = sin.read();
   if (ch == -1) break;
   buf[index++] = (byte)ch;
   //out.println(ch);
}
byte[] buf2 = new byte[index];
System.arraycopy(buf, 0, buf2, 0, index);
String info = new String(buf2, "GBK");
out.println(info);

解决方案 »

  1.   

    Stream   sin   =   Page.Request.InputStream ;
    byte[]   buf   =   new   byte[sin.Length];
            int numBytesToRead = (int) sin.Length;
            int numBytesRead = 0;
            while (numBytesToRead > 0) 
            {
                // Read may return anything from 0 to numBytesToRead.
                int n = s.Read(buf, numBytesRead, numBytesToRead);
                // The end of the file is reached.
                if (n==0)
                    break;
                numBytesRead += n;
                numBytesToRead -= n;
            }
            s.Close();String   info   =  Encoding.GetEncoding("GBK").GetString( bytes );
    out.println(info);
      

  2.   

    Stream       sin       =       Page.Request.InputStream   ;
    byte[]       buf       =       new       byte[sin.Length];
                    int   numBytesToRead   =   (int)   sin.Length;
                    int   numBytesRead   =   0;
                    while   (numBytesToRead   >   0)  
                    {
                            //   Read   may   return   anything   from   0   to   numBytesToRead.
                            int   n   =   s.Read(buf,   numBytesRead,   numBytesToRead);
                            //   The   end   of   the   file   is   reached.
                            if   (n==0)
                                    break;
                            numBytesRead   +=   n;
                            numBytesToRead   -=   n;
                    }
                    s.Close();String       info       =     Encoding.GetEncoding( "GBK ").GetString(   buf );
    out.println(info);
      

  3.   

    Stream               sin               =               Page.Request.InputStream       ;
    byte[]               buf               =               new               byte[sin.Length];
                                    int       numBytesToRead       =       (int)       sin.Length;
                                    int       numBytesRead       =       0;
                                    while       (numBytesToRead       >       0)    
                                    {
                                                    //       Read       may       return       anything       from       0       to       numBytesToRead.
                                                    int       n       =       s.Read(buf,       numBytesRead,       numBytesToRead);
                                                    //       The       end       of       the       file       is       reached.
                                                    if       (n==0)
                                                                    break;
                                                    numBytesRead       +=       n;
                                                    numBytesToRead       -=       n;
                                    }
                                    s.Close();String               info               =           Encoding.GetEncoding(   "GBK   ").GetString(       buf   );
    Console.WriteLine(info);