方法1
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(RecordUrl);
//声明一个HttpWebRequest请求
request.Timeout = 6000;
//设置连接超时时间
request.Headers.Set("Pragma", "no-cache");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//返回响应
Stream streamReceive = response.GetResponseStream();
//获取服务器的文件流
Encoding encoding = Encoding.GetEncoding("GB2312");
StreamReader streamReader = new StreamReader(streamReceive, encoding);
string strResult = streamReader.ReadToEnd();
方法2
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(RecordUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
if (responseStream == Stream.Null)
{
//得不到文件
Response.Write("<script>alert('无效录音文件或无效录音文件地址!')</script>");
}
方法3
if (System.IO.File.Exists(RecordUrl))
{
Response.Redirect(RecordUrl);
}
else
{
Response.Write("<script>alert('无效录音文件或无效录音文件地址!')</script>");
}
方法4
WebRequest myre = WebRequest.Create(RecordUrl); //验证是否可以连接服务器
myre.Timeout = 3000;//设置3秒超时
myre.GetResponse();//请求响应
Response.Redirect(RecordUrl);