本人初学c#,想知道如何验证某个URL地址是否正确,谢谢各位兄弟捧场,呵呵 (?<http>(http:[/][/]|www.)([a-z]|[A-Z]|[0-9]|[/.]|[~])*) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 更多内容看http://www.regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2 我是用webservice呵呵,没有用验证控件,还有,不是验证地址是否正确是那个地址是否可以访问,是否真的存在那个地址,我没说明白,呵呵谢谢楼上 这个不好判断,前阵子也做过这样的验证,只能做到URL里面没有“://”的话在URL前面加“HTTP://”因为URL的前缀比较多http,https,ftp,rtsp等等 使用RegularExpressionValidator控件,验证表达式为“http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?” 我不是验证地址是否正确,不是规则表达式是判断URL是否存在,呵呵,据说问题很高深???呵呵 是不是在DOS下用ping 的命令一样,能拼通就存在了。 先做一个httpmodule,让每个请求都通过这个module,然后在module中判断请求的地址是否存在。应该可以的。 能ping通,不一定是web服务器,也许只是一台很普通的机器 看看HttpWebRequest和HttpWebResponse,看是否能根据返回的东西来判断 Dim url As String url = "http://xxxx........" Dim Htp As XMLHTTPRequest Htp = New XMLHTTPRequest() Htp.Open ("POST", url, False) Htp.send() If Htp.Status = 200 Then '有效 Else ’无效 End If guoyan19811021(吉祥) ( ) 信誉:94 高,我试试,呵呵 Dim url As String url = "http://xxxx........" Dim Htp As XMLHTTPRequest Htp = New XMLHTTPRequest() Htp.Open ("POST", url, False) Htp.send() If Htp.Status = 200 Then '有效 Else ’无效 End If有类似C#的写法么?? 解决问题思想,如果一个url有效改能解析出其ip地址,所以,只要能有ip那么就有效。代码如下using System.Net;try{ IPHostEntry iphosts=Dns.Resolve(要验证的url); foreach(IPAddress ip in iphosts.AddressList) { long Address=ip.Address; this.listBoxIPs.Items.Add(Address.ToString()); this.listBoxIPs.Items.Add(" "+ip.ToString()); } textBoxHostName.Text=iphosts.HostName;}catch(Exception ex){ MessageBox.Show("Can't Access"+ex.Message,"Exception");}楼主可根据需要改写一下啊。 string url; url="http://www.csdn.net"; MSXML2.XMLHTTP40 htp=new MSXML2.XMLHTTP40(); htp.open("post",url,false,"",""); htp.send("test"); if (htp.status==200) { MessageBox.Show("有效"); } else { MessageBox.Show("无效"); } try { System.Net.WebRequest myRequest = System.Net.WebRequest.Create("http://192.168.0.6/rootserver/DirService.asmx"); System.Net.WebResponse myResponse = myRequest.GetResponse(); return "ok"; } catch(Exception ex) { return ex.Message.ToString(); } 子窗口传值到父窗口 GridView排序 JAVA端发布Webservice返回list,.Net客户端获取不到吗?【急,在线等!】 用session和url传递参数值有何不同 谁有没有好点的用户注册邮件通知代码 不小心发现居然升星了,散分200,顺道祝大家工作愉快,天天进步! 谁能教我个除法? 哪位能提供 统计分析 功能的源码? asp mvc 是如何提交的 高分求vss的web插件(通过web方式使用vss) 以前没做过,紧急寻求帮助--关于asp.net中新建文件夹,并拷贝文件到此文件夹的问题。 急,请求帮助,在线等待
http://www.regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2
因为URL的前缀比较多
http,https,ftp,rtsp等等
url = "http://xxxx........"
Dim Htp As XMLHTTPRequest
Htp = New XMLHTTPRequest()
Htp.Open ("POST", url, False)
Htp.send()
If Htp.Status = 200 Then
'有效
Else
’无效
End If
高,我试试,呵呵
url = "http://xxxx........"
Dim Htp As XMLHTTPRequest
Htp = New XMLHTTPRequest()
Htp.Open ("POST", url, False)
Htp.send()
If Htp.Status = 200 Then
'有效
Else
’无效
End If
有类似C#的写法么??
代码如下
using System.Net;
try
{
IPHostEntry iphosts=Dns.Resolve(要验证的url);
foreach(IPAddress ip in iphosts.AddressList)
{
long Address=ip.Address;
this.listBoxIPs.Items.Add(Address.ToString());
this.listBoxIPs.Items.Add(" "+ip.ToString());
}
textBoxHostName.Text=iphosts.HostName;
}
catch(Exception ex)
{
MessageBox.Show("Can't Access"+ex.Message,"Exception");
}楼主可根据需要改写一下啊。
url="http://www.csdn.net";
MSXML2.XMLHTTP40 htp=new MSXML2.XMLHTTP40();
htp.open("post",url,false,"","");
htp.send("test");
if (htp.status==200)
{
MessageBox.Show("有效");
}
else
{
MessageBox.Show("无效");
}
{
System.Net.WebRequest myRequest = System.Net.WebRequest.Create("http://192.168.0.6/rootserver/DirService.asmx");
System.Net.WebResponse myResponse = myRequest.GetResponse();
return "ok";
}
catch(Exception ex)
{
return ex.Message.ToString();
}