Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

What's wrong with this code? HttpWebRequest

Question posted by: Richard Aubin (Guest) on November 20th, 2005 11:26 PM
The following code is supposed to fetch an this page from the specified url
then display the contents.

The only problem is that I'm only getting the following as the response,
when the page is actually much longer:

<html>
<head>

----

Console Application

Imports System
Imports System.IO
Imports System.Net

Module Module1

Sub Main()
'Address of URL
Dim URL As String = http://www.csharpcorner.com/default.asp
Dim request As WebRequest = WebRequest.Create(URL)
Dim response As WebResponse = request.GetResponse()
Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
Dim str As String = reader.ReadLine()

Do While str.Length > 0
Console.WriteLine(str)
str = reader.ReadLine()
Loop

Console.ReadLine("press enter to continue)

End Sub

End Module


Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Richard Aubin's Avatar
Richard Aubin
Guest
n/a Posts
November 20th, 2005
11:26 PM
#2

Re: What's wrong with this code? HttpWebRequest
Nevermind, found out what it was...

Do While str.Length > 0

It encounted an empty line ;)


"Richard Aubin" <rcaubin@safe-mailDOTnet> wrote in message
news:OiJHF2BgEHA.1656@TK2MSFTNGP10.phx.gbl...[color=blue]
> The following code is supposed to fetch an this page from the specified[/color]
url[color=blue]
> then display the contents.
>
> The only problem is that I'm only getting the following as the response,
> when the page is actually much longer:
>
> <html>
> <head>
>
> ----
>
> Console Application
>
> Imports System
> Imports System.IO
> Imports System.Net
>
> Module Module1
>
> Sub Main()
> 'Address of URL
> Dim URL As String = http://www.csharpcorner.com/default.asp
> Dim request As WebRequest = WebRequest.Create(URL)
> Dim response As WebResponse = request.GetResponse()
> Dim reader As StreamReader = New[/color]
StreamReader(response.GetResponseStream())[color=blue]
> Dim str As String = reader.ReadLine()
>
> Do While str.Length > 0
> Console.WriteLine(str)
> str = reader.ReadLine()
> Loop
>
> Console.ReadLine("press enter to continue)
>
> End Sub
>
> End Module
>
>[/color]



 
Not the answer you were looking for? Post your question . . .
183,940 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors