直接帖代码吧!有什么问题可以M我!
调用的命名空间是:using System.Net;
string URL = HttpUtility.UrlDecode("http://img.shengri.com/Resource/pic/21/530.gif");
HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL);
myWebRequest.AllowAutoRedirect = false;
try
{
HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();
if (myWebResponse.StatusCode == HttpStatusCode.OK)
{
Response.Write("True");
}
else
{
Response.Write("False");
}
}
catch(WebException webExcp)
{
WebExceptionStatus status = webExcp.Status;
if (status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse httpResponse = (HttpWebResponse)webExcp.Response;
if((int)httpResponse.StatusCode == 404)
{
Response.Write("The server returned protocol error:");
Response.Write((int)httpResponse.StatusCode + " - " + httpResponse.StatusCode);
}
}
}