Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > Web Request hangup

Reply
Thread Tools

Web Request hangup

 
 
terpanther terpanther is offline
Junior Member
Join Date: May 2009
Posts: 2
 
      05-27-2009
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 = "xxxxxxxxxxxxxxxf"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("cons umer_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
 
Reply With Quote
 
 
 
 
terpanther terpanther is offline
Junior Member
Join Date: May 2009
Posts: 2
 
      05-27-2009
I put *** hangs here *** on the wrong line of code. It actually hangs the second time through on the GetReponse line.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Asterisk detecting POTS line hangup Sparks UK VOIP 4 07-03-2005 09:06 AM
no hangup after call elmar bschorer Cisco 3 02-20-2005 02:37 PM
Treeview causing hangup =?Utf-8?B?Y2xzbWl0aDY2?= ASP .Net 0 12-09-2004 04:37 PM
Client will not initiate a hangup on an internet connection =?Utf-8?B?U2hpcmxlZQ==?= Wireless Networking 0 09-26-2004 06:47 PM
Visual Studio .Net 2003 IDE Hangup Manuel Bua ASP .Net 1 10-20-2003 06:02 PM



Advertisments