I do not get any Response of httpWebRequest in windows server 2012 R2.
I'm using httpWebRequest in vs 2017 VB.NET. It works fine in windows 10. But I do not get any Response in windows server 2012 R2. How to fix it?
Re: I do not get any Response of httpWebRequest in windows server 2012 R2.
It's the exact same code?
I'm not sure that no response is even possible. Perhaps you'll have to show us how you are sending the response. In my experience, you get one of three alternatives: A response, an exception, or a hang. You wouldn't be able to avoid noticing that last one.
Re: I do not get any Response of httpWebRequest in windows server 2012 R2.
Code:
Public Sub mRequest()
If taskRun = True Then
Task.Run(Sub()
Try
OnPingTime.Invoke("Info", "Connecting ...." & Me.actionURL)
Dim formUrl As String = "URL"
Try
Dim req As HttpWebRequest = CType(WebRequest.Create(formUrl), HttpWebRequest)
req.Method = "GET"
req.Host = "HOST"
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
req.Headers.Add("Accept-Language", "en-US,en;q=0.5")
req.Headers.Add("Accept-Encoding", "gzip, deflate")
req.UserAgent = UserAgent
req.CookieContainer = cook
req.Referer = Me.actionURL
req.KeepAlive = True
'req.Proxy = proxy;
Const contentType As String = "application/x-www-form-urlencoded; charset=UTF-8"
req.ContentType = contentType
Try
Dim resp As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
Dim stremResponse As Stream = resp.GetResponseStream()
If resp.ContentEncoding.ToLower().Contains("gzip") Then
stremResponse = New GZipStream(stremResponse, CompressionMode.Decompress)
ElseIf resp.ContentEncoding.ToLower().Contains("deflate") Then
stremResponse = New DeflateStream(stremResponse, CompressionMode.Decompress)
End If
Dim srd As New StreamReader(stremResponse)
response = srd.ReadToEnd()
Dim html As New HtmlDocument()
html.LoadHtml(response)
Catch ex As WebException
If ex.Status = WebExceptionStatus.ProtocolError OrElse ex.Status = WebExceptionStatus.ConnectFailure OrElse ex.Status = WebExceptionStatus.NameResolutionFailure OrElse ex.Status = WebExceptionStatus.Timeout OrElse ex.Status = WebExceptionStatus.ProxyNameResolutionFailure Then
Dim response = TryCast(ex.Response, HttpWebResponse)
If response IsNot Nothing Then
If CInt(response.StatusCode) >= 500 Then
Thread.Sleep(1000)
If AutoRetry = True Then Start()
Else
End If
Else
Thread.Sleep(1000)
If AutoRetry = True Then Start()
End If
Else
End If
End Try
Catch e As Exception
'_msg.Add(e.Message)
Thread.Sleep(1000)
If AutoRetry = True Then Start()
End Try
Catch ex As Exception
End Try
End Sub)
End If
End Sub
This is My Code. I just Get Connecting ....
Re: I do not get any Response of httpWebRequest in windows server 2012 R2.
Please check the code above.
Re: I do not get any Response of httpWebRequest in windows server 2012 R2.
I would suggest that for testing purposes you should take it out of the task. That would make it easier to step through and debug. You may be getting a hang. Since you are running this in a Task, a hang would essentially go on forever without you ever knowing about it. The Task simply wouldn't complete. If I remember right, the hang would come on GetResponse. Solving it is a different matter, as I have yet to see it consistently, but the first step would be to figure out if that really was the issue.
Re: I do not get any Response of httpWebRequest in windows server 2012 R2.
If that's the exact code you're using, with no alterations what so ever, I can tell you exactly what the problem is (1). Why it worked in Win10, I couldn't say, except that odds are it probably didn't and the exception was swallowed (2). Ick... I wished now I hadn't looked at that code a second time, it's making me twitch(3).
-tg
(1) - reference the formUrl variable value
(2) - referencing the empty catch
(3) - good grief, empty else...end if and the previously mentioned empty catch.