私は(PHPの関数をシミュレートするには - のfile_get_contents)C#を使用してHTMLコンテンツをロードしようとしていたときに、HTMLで画像を読み込むことができません、次のコードを使用して:C#のWebクライアント:負荷Webページ
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タグはどのように見えますか?また、なぜ単にDownloadStringではなく、DownloadDataとEncoding.ASCIIを使用していますか? –
文字列を読み終えたら、文字列全体をWebページに出力して内容を表示するだけです。 imgタグはです。私はhttp://www.devprise.com/2006/07/14/c-method-to-mimic-php-file_get_contents/に従った。 – phlai
私はDownloadStringを試しただけで、PHPのfile_get_contentsとは違って画像もロードされないようです。 – phlai