views:

400

answers:

2

I am running this piece of code to get the source code (as string) of my webpage.

The problem is why this function returns 404 error?

Private Function getPageSource(ByVal URL As String) As String
    Dim webClient As New System.Net.WebClient()
    Dim strSource As String = webClient.DownloadString(URL)
    webClient.Dispose()
    Return strSource
End Function
A: 

Try this

using System; using System.IO; using System.Net; using System.Text;

public static void GetFile 
        ( 
        string strURL, 
        string strFilePath 
        ) 
    { 

        WebRequest myWebRequest = WebRequest.Create(strURL);  

        WebResponse myWebResponse = myWebRequest.GetResponse();  

        Stream ReceiveStream = myWebResponse.GetResponseStream(); 

        Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); 

        StreamReader readStream = new StreamReader( ReceiveStream, encode ); 

        string strResponse=readStream.ReadToEnd(); 

        StreamWriter oSw=new StreamWriter(strFilePath); 

        oSw.WriteLine(strResponse); 

        oSw.Close(); 

        readStream.Close(); 

        myWebResponse.Close(); 

    } 
ANIL MANE
Pardon me, but for what reason should i try this solution?
John
A: 

Hi There,

Has anyone got answer for this. It is annoying and looks like some platform issue which is not allowing the response to come through.

Thanks, Nimesh

Nimesh