Web Request hangup

Discussion in 'Software' started by terpanther, May 27, 2009.

  1. terpanther

    terpanther

    Joined:
    May 27, 2009
    Messages:
    2
    This is very frustrating and I believe it to be a bug in the framework. We have tried everything we can think of to fix this and it happens consistently.

    This statement in the below code:

    Dim WebResp as HTTPWebResponse = DirectCast WebReq.GetResponse(), HttpWebResponse)

    That statement will hang every single time if the user closes or clicks back on the browser and tries the button click again. It will work the first time, but hangs until timeout in subsequent attempts. Every time. Closing the streams, etc. doesn't fix it. This happens on multiple machines and platforms as well as Framework 1.1 and 2.

    'Build Web Request

    Dim WebReq As HttpWebRequest = DirectCast(WebRequest.Create(strPage), HttpWebRequest)
    'Authentication

    Dim auth As String = "xxxxxxxx:xxxxxxxxf"Dim authBytes As Byte() = Encoding.UTF8.GetBytes(auth.ToCharArray())
    WebReq.Headers("Authorization") = "Basic " & Convert.ToBase64String(authBytes)

    'Our method is post, otherwise the buffer (postvars) would be useless

    WebReq.Method = "POST"

    'We use form contentType, for the postvars.

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

    'The length of the buffer (postvars) is used as contentlength.

    WebReq.ContentLength = buffer.Length

    'We open a stream for writing the postvars

    Dim PostData As Stream = WebReq.GetRequestStream() *** hangs here ***
    'Now we write, and afterwards, we close. Closing is always important!

    PostData.Write(buffer, 0, buffer.Length)

    ' Close the Stream

    PostData.Close()

    'Get the response handle, we have no true response yet!

    Dim WebResp As HttpWebResponse = DirectCast(WebReq.GetResponse(), HttpWebResponse)
    Dim strResponse As String

    strResponse = WebResp.StatusCode

    Dim streamResponse As Stream = WebResp.GetResponseStream()
    Dim streamRead As New StreamReader(streamResponse)

    Dim responseString As String

    responseString = streamRead.ReadLine

    streamResponse.Close()

    streamRead.Close()

    WebResp.Close()

    streamResponse = Nothing

    streamRead = Nothing

    WebResp = Nothing

    GC.Collect()

    ' The Following code gets the return variables into pairs

    Dim rPairs As New NameValueCollection
    Dim pairs As String() = responseString.Split("&"c)

    For Each pair As String In pairsDim values As String() = pair.Split("="c)
    rPairs.Add(values(0), values(1))

    Next

    If strResponse = HttpStatusCode.OK Then

    If rPairs("response_code") = "1" Then

    ' Collect Garbage and see if that will end the session

    GC.Collect()

    HttpContext.Current.Response.Redirect(rPairs("consumer_url"))

    rPairs = Nothing

    HttpContext.Current.Response.Close()

    HttpContext.Current.Response.End()

    Return True

    Else

    'Tools.EventLogger.LogEvent((rPairs("response_code") & ":") + rPairs("response_msg"), EventLogEntryType.[Error])

    HttpContext.Current.Response.Write("Status1 Code: " & WebResp.StatusCode)

    Return False

    End If
     
    terpanther, May 27, 2009
    #1
    1. Advertising

  2. terpanther

    terpanther

    Joined:
    May 27, 2009
    Messages:
    2
    Correction

    I put *** hangs here *** on the wrong line of code. It actually hangs the second time through on the GetReponse line.
     
    terpanther, May 27, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2hpcmxlZQ==?=

    Client will not initiate a hangup on an internet connection

    =?Utf-8?B?U2hpcmxlZQ==?=, Sep 26, 2004, in forum: Wireless Networking
    Replies:
    0
    Views:
    560
    =?Utf-8?B?U2hpcmxlZQ==?=
    Sep 26, 2004
  2. elmar bschorer

    no hangup after call

    elmar bschorer, Feb 19, 2005, in forum: Cisco
    Replies:
    3
    Views:
    1,263
    Ivan OstreŇ°
    Feb 20, 2005
  3. Sparks
    Replies:
    4
    Views:
    10,962
  4. Joe Harrison
    Replies:
    16
    Views:
    967
    Thomas Rankin
    Aug 3, 2005
  5. TJ

    Clean install Win ME hangup

    TJ, Apr 10, 2006, in forum: Computer Support
    Replies:
    3
    Views:
    355
    philo
    Apr 10, 2006
Loading...

Share This Page