开发者

The remote server returned an error: (404) Not Found

开发者 https://www.devze.com 2022-12-28 22:31 出处:网络
I am running this piece of code to get the source code (as string) of my webpage. The problem is why this func开发者_开发问答tion returns 404 error?

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

The problem is why this func开发者_开发问答tion 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


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(); 

    } 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号