|
-
Sep 4th, 2018, 11:16 AM
#1
Thread Starter
Member
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?
 please 
-
Sep 4th, 2018, 11:21 AM
#2
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.
My usual boring signature: Nothing
 
-
Sep 4th, 2018, 11:29 AM
#3
Thread Starter
Member
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 ....
 please 
-
Sep 4th, 2018, 11:30 AM
#4
Thread Starter
Member
Re: I do not get any Response of httpWebRequest in windows server 2012 R2.
Please check the code above.
Last edited by buzz4rd; Sep 4th, 2018 at 11:31 AM.
Reason: duplicate content
 please 
-
Sep 4th, 2018, 02:59 PM
#5
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.
My usual boring signature: Nothing
 
-
Sep 5th, 2018, 06:59 AM
#6
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|