1

I am writing code where I am trying to grab the HTML from a DNS report online (http://viewdns.info/dnsreport/?domain=google.com), but I am having some issues. The one line of the HTML file (Line 231) that I actually need is cutting itself off after around 680 characters. All of the lines after the important one are reading correctly, however. The code for grabbing the HTML is shown below, and I have tried it in two separate ways. This is the first way I tried:

Public Function getWebResourceData(ByVal strURL As String) As String
    Dim webClient As New System.Net.WebClient
    Dim result As String = webClient.DownloadString("http://viewdns.info/dnsreport/?" &        TextBox1.Text)
    return result
End Function

And this is the second:

Public Function getWebResourceData(ByVal strURL As String) As String
    Dim rt As String = ""
    Dim wRequest As WebRequest
    Dim wResponse As WebResponse
    Dim SR As StreamReader
    wRequest = WebRequest.Create(strURL)
    wResponse = wRequest.GetResponse
    SR = New StreamReader(wResponse.GetResponseStream)
    rt = SR.ReadToEnd
    SR.Close()
    return rt
End Function

Im really not sure what else could be wrong at this point. I have also tried saving the result to a text file to see if that was the issue, but that was incorrect as well. I have looked into the hex codes for the area where the string is stopping, but there isn't anything out of the ordinary. The split occurs between the back to back alligator brackets (shown as parentheses) here: (/tr)(tr)

But there are numerous sets of these tags throughout the HTML that there are no issues with.

Jordan McGowan
  • 197
  • 1
  • 1
  • 9
  • To determine if it is a problem with the website or not (unlikely to be the BCL), did you try reading a different website altogether? – Ahmed ilyas Jun 06 '14 at 19:59
  • This issue continues to happen with the site that I am testing: http://viewdns.info/dnsreport/?domain=google.com no matter what domain you put in – Jordan McGowan Jun 06 '14 at 20:02

1 Answers1

0

Both of your functions don't return what they have read. I have tested the second one and it works correctly.

Sub Main
    Dim ret = getWebResourceData("http://viewdns.info/dnsreport/?domain=google.com")
    Console.WriteLine(ret.Length)
     ' Output = 21605
End Sub

Public Function getWebResourceData(ByVal strURL As String) As String
    Dim rt As String = ""
    Dim wRequest As WebRequest
    Dim wResponse As WebResponse
    Dim SR As StreamReader
    wRequest = WebRequest.Create(strURL)
    wResponse = wRequest.GetResponse
    SR = New StreamReader(wResponse.GetResponseStream)
    rt = SR.ReadToEnd
    SR.Close()
    return rt
End Function
Steve
  • 213,761
  • 22
  • 232
  • 286
  • I have left out the return statements. I have been using return statements and tried showing the results in a MsgBox() but it hasn't worked. What site did you test it on? – Jordan McGowan Jun 06 '14 at 20:19
  • I have tested using [LinqPAD](http://www.linqpad.net/), I don't think that showing all that kind of data with a MessageBox is reliable. A simple console application with a Console.WriteLine is better for this – Steve Jun 06 '14 at 20:25
  • The issue that I am having is only with http://viewdns.info/dnsreport/?domain=google.com The code gets the HTML, just not all of it. – Jordan McGowan Jun 06 '14 at 20:27
  • Exactly what I have tested above. By the way, I have saved the content of the return string in a file on disk and then opened that file with a browser. It works (well apart from missing images) – Steve Jun 06 '14 at 20:28
  • Interesting. I copied the code you posted and it is not working. It will not give the actual report, just the header and footer... – Jordan McGowan Jun 06 '14 at 20:32
  • But if you print the length of the returned string without trying to do anything with the string, did you get a value in the range of 680 or 21000? – Steve Jun 06 '14 at 20:37
  • The 680 just refers to line 230 in the output. I get a value around 9500 for total characters. – Jordan McGowan Jun 06 '14 at 20:40
  • 1
    I just figures it out...The format of the url I was using was wrong. Your help was very appreciated though!!! – Jordan McGowan Jun 06 '14 at 20:42