Go Back   Velocity Reviews > General Computer Discussion > Software
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
Old 05-27-2009, 01:38 PM   #1
Default Web Request hangup


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


terpanther
terpanther is offline   Reply With Quote
Old 05-27-2009, 01:40 PM   #2
terpanther
Junior Member
 
Join Date: May 2009
Posts: 2
Default Correction
I put *** hangs here *** on the wrong line of code. It actually hangs the second time through on the GetReponse line.


terpanther
terpanther is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTPS Request Dump in java Jolly Kumar Software 0 08-11-2009 05:25 AM
Request for access code request for access code MCITP 1 10-23-2008 03:42 PM
Request zeg eens aaa een serie dvd(s) bizzmaxx DVD Video 0 04-16-2006 08:55 PM
only part of a readprocessmemory or writeprocessmemory request was completed John A+ Certification 3 10-04-2005 11:59 AM
dvd request **TheWhiteAssassin***UK* DVD Video 2 09-12-2005 06:43 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46