HttpWebRequest is throwing connection timeout error after several requests

After couple of execution, invoke code activity is encountering exception.

Dim fr As System.Net.HttpWebRequest
Dim targetURI As New Uri(strURL)

fr = DirectCast(HttpWebRequest.Create(targetURI), System.Net.HttpWebRequest)

Dim webProxy As IWebProxy = New WebProxy(strIpAddressAndPort)
webProxy.Credentials = New NetworkCredential(strProxyUsername, strProxyPassword)
fr.Proxy = webProxy
fr.Timeout = 90000
fr.KeepAlive = True

msgbox(strURL)
fr.Headers.Add(“Authorization”, jwtOutput)
msgbox(jwtOutput)
fr.Headers.Add(“zapiAccessKey”, “MWExM2QyZTYtYzBlMi0zODI5LWIzMjUtZWNjZDJjMDBkODQ5IDYyMjhlODliYzg4ZjEwMDA2ODMyNWRhNCBVU0VSX0RFRkFVTFRf”)
msgbox(“hi inside”)
Using res As HttpWebResponse = DirectCast(fr.GetResponse(), System.Net.HttpWebResponse)
msgbox(“hi inside response”)
webRes = res
Dim html As String = New StreamReader(res.GetResponseStream()).ReadToEnd()
strHtml = html
fr.GetResponse.Close()
res.Dispose()
res.Close()
End Using

Any suggestions if any changes are required?

After adding ```
request.ServicePoint.ConnectionLeaseTimeout = 5000;
request.ServicePoint.MaxIdleTime = 5000;


https://stackoverflow.com/questions/5827030/httpwebrequest-times-out-on-second-call

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.