![]() |
|
|
|
#1 |
|
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 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 |
|
|
|
|
|
|
#2 |
|
Junior Member
Join Date: May 2009
Posts: 2
|
I put *** hangs here *** on the wrong line of code. It actually hangs the second time through on the GetReponse line.
terpanther |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |