网络上的一个文件,怎么判断它是本身不存在,还是别的原因:像网络出现问题
解决方案 »
- 求c# winform datagridview实现数据编辑的框架或模板。
- c# sql语句条件里有汉字,选出来的结果为空
- 在SQL SERVER 2005可以使用.NET REMOTING吗?
- 数据库,窗口方面的问题!
- TextBox如何格式化IP?
- 高手帮帮我啊,救命啊,我都想了一个星期了,没有多少分了,全给了。。。
- wince编程应该注意哪些事项
- 如何使DataGrid的分页码数字:1 2 3的位置放到左边,缺省在右边的?
- 寻找天下兄
- c#如何实现 想酷狗 和 windows自带播放器那样的任务栏小按钮
- 哪里有允许上传一个90M文件的免费空间?
- 控件问题,openFileDialog打开文件对话框。
{
i++;
StateObject state = (StateObject)ar.AsyncState;
Socket handle = state.workSocket;
int read = handle.EndReceive(ar);
if (read > 0)
{
string data = Encoding.ASCII.GetString(state.buffer, 0, read);
state.sb.Append(data);
handle.BeginReceive(state.buffer, 0, StateObject.buffSize, 0, new AsyncCallback(readCallBack), state);
}
else
{
if(state.sb.Length> 0)
{
state.sb.Append(" 共接收了" + i.ToString() + "次");
MessageBox.Show(state.sb.ToString());
}
handle.Close();
}
}
或者向一个确定存在的URL发出Request
如果没有得到响应,那么就是网络出现问题
参考:
http://topic.csdn.net/u/20080122/21/8cdb3b9d-f335-403f-a62e-55e4ea5aa29d.htmlusing System.Net; namespace libinbin
{
class Program
{
static int Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("请输入地址");
return -1;
} string url = args[0].ToString();
System.Net.HttpWebResponse res = null;
HttpStatusCode hsc; try
{
System.Net.HttpWebRequest myRequest = (HttpWebRequest)System.Net.WebRequest.Create(url);
myRequest.Method = "HEAD";
res = (HttpWebResponse)myRequest.GetResponse();
hsc = res.StatusCode;
}
catch (WebException wex)
{ } Console.WriteLine(hsc); return (Convert.ToInt32(hsc) == 200) ? 0 : Convert.ToInt32(hsc);
}
}
}