Edited my code to use WebClient...still doesnt work
string hhtmlurl = /Thumbnail.aspx?productID=23&Firstname=jimmy&lastnight=smith;
string strFileName = string.Format("{0}_{1}", hfUserID.Value, Request.QueryString["pid"].ToString() + documentID.ToString());
WebClient client = new WebClient();
client.DownloadFile("http://www.url.ca/" + hhtmlurl.Value + "card=1", strFileName);
WebClient.DownloadFile
可能会更容易。
Instead of FileStream, use the WebClient
class, which offers the delightfully simple DownloadFile()
method:
WebClient client = new WebClient();
client.Downloadfile("http://www.url.ca/" + hhtmlurl + "card=1", strFileName);
Try this method. This will give you string return for the entire html content. Write this string in whatever file you want
public string GetHtmlPageContent(string url)
{
HttpWebResponse siteResponse = null;
HttpWebRequest siteRequest = null;
string content= string.Empty;
try
{
Uri uri = new Uri(url);
siteRequest = (HttpWebRequest)HttpWebRequest.Create(url);
siteResponse = (HttpWebResponse)siteRequest.GetResponse();
content = GetResponseText(siteResponse);
}
catch (WebException we)
{
// Log error
}
catch (Exception e2)
{
// Log error
}
return content;
}
public string GetResponseText(HttpWebResponse response)
{
string responseText = string.Empty;
if (response == null)
return string.Empty;
try
{
StreamReader responseReader = new StreamReader(response.GetResponseStream());
responseText = responseReader.ReadToEnd();
responseReader.Close();
}
catch (Exception ex)
{
// Log error
}
return responseText;
}
Hope this will help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.