getrequeststream error

To everyone:

below is a partial code that i am doing for parsing an html. this works fine on the first access. but at the second round it is hanging on getrequeststream(highligted in red). if there is anyone of you who have encounted this, please advise me of the solution.

Thank you so much.


Arequest.ContentType = "application/x-www-form-urlencoded"

Arequest.ContentLength = postData.Length

Arequest.Method = "POST"

Arequest.AllowAutoRedirect = False

Arequest.Timeout = 100000

'adsasddf

'Dim sCookieContainer As CookieContainer

'Arequest.CookieContainer = New CookieContainer

'Dim requestStream As Stream = Arequest.GetRequestStream()

Dim requestStream As Stream

requestStream = Nothing

requestStream = Arequest.GetRequestStream()

Dim postBytes As Byte() = Encoding.ASCII.GetBytes(postData)

requestStream.Write(postBytes, 0, postBytes.Length)

requestStream.Close()

requestStream = Nothing

Aresponse = CType(Arequest.GetResponse(), HttpWebResponse)




Answer this question

getrequeststream error

  • Chirag Rai

    try closing your response
  • Guri

    There's another bug: You might send a wrong Content-Length header. Never use the post data's string length. Use the size of postBytes (i.e. the number of bytes after encoding your post data).

    I'd also avoid ASCIIEncoding. This will break immediately once you want to post Latin 1 or other non-ASCII characters. Use UTF-8 or ISO-8859-1.


    // UTF-8
    Encoding enc = Encoding.UTF8;

     


    or


    // ISO-8859-1
    Encoding enc = Encoding.GetEncoding(28591);

     



  • getrequeststream error