远程服务器返回错误:(404)未找到
问题描述:
我运行的我webpage.远程服务器返回错误:(404)未找到
这段代码获得源代码(如字符串)的问题是,为什么这个函数会返回404错误?
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
答
试试这个
使用系统;使用System.IO的 ;使用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();
}
+1
请原谅我,但为什么我应该尝试这种解决方案? – John 2010-05-03 08:56:03
1)对于源代码,你的意思是HTML的权利? 2)你能粘贴一个示例URL吗? – 2010-04-30 12:06:36
Yeap。这是真的 – John 2010-04-30 12:11:15
示例网址是http://www.kickstart.gr/ – John 2010-05-03 08:54:43