c#获取远程图片文件流代码

/// <summary>
/// 获取图片流
/// </summary>
/// <param name=”url”>图片URL</param>
/// <returns></returns>
public static Stream GetRemoteImage(string url)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = “GET”;
request.ContentLength = 0;
request.Timeout = 20000;
HttpWebResponse response = null;

try
{
response = (HttpWebResponse)request.GetResponse();
return response.GetResponseStream();
}
catch
{
return null;
}
}

 

直接调用就好了.

发表评论

电子邮件地址不会被公开。 必填项已用*标注