Arun Raheja

Arun Raheja

  • NA
  • 1
  • 1.1k

Error in Calling HTTP Api in .net Framework

Nov 2 2014 11:29 PM
The underlying connection was closed: An unexpected error occurred on a send.
 
I am getting Above Error when i run that code on the server.
======================================================== 
Dim response As String = String.Empty
Dim MyRetVal As String = "Invalid"
Dim requestTOService As System.Net.HttpWebRequest
Dim auth_userid As Int64 = 377686
Dim api_key As String = "AdvY0zXBg9hNnqqXXuaPZLEXfIcDYUCb"
Try
System.Net.ServicePointManager.ServerCertificateValidationCallback = (Function(sender, certificate, chain, sslPolicyErrors) True)
ServicePointManager.MaxServicePointIdleTime = 1000
ServicePointManager.UseNagleAlgorithm = True
ServicePointManager.Expect100Continue = True
ServicePointManager.CheckCertificateRevocationList = True
ServicePointManager.DefaultConnectionLimit = _
ServicePointManager.DefaultPersistentConnectionLimit
requestTOService = System.Net.HttpWebRequest.Create("https://httpapi.com/api/domains/available.xml?auth-userid=" + auth_userid.ToString() + "&api-key=" + api_key + "&domain-name=" + MyDomain + "&tlds=" + tld)
requestTOService.Method = System.Net.WebRequestMethods.Http.Get
requestTOService.ContentType = "application/x-www-form-urlencoded"
requestTOService.KeepAlive = False
Dim responseFromService As System.Net.HttpWebResponse
responseFromService = CType(requestTOService.GetResponse(), System.Net.HttpWebResponse)
Dim readResponse As New System.IO.StreamReader(responseFromService.GetResponseStream())
response = readResponse.ReadToEnd
'ReadResponse
If response.Contains("available") Or response.Contains("Available") Then
MyRetVal = "available"
End If
Catch ex As WebException
If ex.Response IsNot Nothing Then
Dim httpwebres As System.Net.HttpWebResponse = ex.Response
Dim respSteam As New StreamReader(httpwebres.GetResponseStream())
 
End If
 
End Try
========================================================
 
 
 
 
 
 
 
 

Answers (1)