我試圖加載使用C#中的HTML內容(模擬PHP函數 - 的file_get_contents)使用下面的代碼:C#Web客戶端:在HTML無法加載圖像時加載網頁
protected string file_get_contents(string fileName)
{
string sContents = string.Empty;
if (fileName.ToLower().IndexOf("http:") > -1)
{ // URL
System.Net.WebClient wc = new System.Net.WebClient();
byte[] response = wc.DownloadData(fileName);
sContents = System.Text.Encoding.ASCII.GetString(response);
} else {
// Regular Filename
System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
sContents = sr.ReadToEnd();
sr.Close();
}
return sContents;
}
然而,這不會在呈現內容時在html中加載圖像。但是,當使用PHP file_get_content時,它會在呈現內容時在HTML中加載圖像。
任何人有任何想法?
你如何渲染內容,以及img標籤是什麼樣的?另外,你爲什麼使用DownloadData和Encoding.ASCII而不僅僅是DownloadString? – 2010-11-26 14:04:20