Problem with HttpWebResponse

Hi,

I have some problem with the following code :

HttpWebResponse result = (HttpWebResponse)req.GetResponse();

//result.ContentLength -> 159

Stream ReceiveStream = result.GetResponseStream();

//result.CharacterSet -> ""
//result.ContentType -> text/html; charset=utf-8
//result.ContentEncoding -> ""
//result.Headers -> Date: Tue, 25 Jul 2006 10:58:47 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Set-Cookie: ASP.NET_SessionId=zmksm055kvyigzmlvxgohqe2; path=/
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 159

StreamReader XMLRead = new StreamReader(ReceiveStream, System.Text.Encoding.UTF8);
String read = XMLRead.ReadLine();

//read is empty!!!

My problems is that the string read is empty....

Have you an idea

Thanks



Answer this question

Problem with HttpWebResponse

  • Eric Krejci

    To read the WebResponse i need to do that :

    byte[] flux = new byte[result.ContentLength+1];

    int longueur = ReceiveStream.Read(flux, 0, (int)result.ContentLength);

    System.Text.Encoding encoding = System.Text.Encoding.UTF8;

    String contenu = encode.GetString(flux, 0, flux.Length));

    Is it normal that i can't use normally the getStream()


  • Muzaffar_Ali99

    try

    string read = XMLRead.ReadToEnd();


  • vande013

    The result is the same as with MLRead.ReadLine();


  • Deepesh Verma

    When you call Stream.Read(), you can't ignore the returning integer since it indicates how many bytes have actually be read.

    For your original issue, you may want to verify if the same code works against the Desktop CLR.

    Cheers,

    Anthony Wong [MSFT]


  • Javier Becerril

    if i had the following code line :

    String size = ReceiveStream.Length;

    I have the following error :

    NotSupportedException : STACK : a System.Net.HttpReadStream.get_Length()


  • Problem with HttpWebResponse