The remote server returned an error: (404) Not Found
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();
}
精彩评论