标题: vbscript能不能通过url对一个文件进行操作? [打印本页] 作者: xuehuiyiwang 时间: 2007-8-3 16:05 标题: vbscript能不能通过url对一个文件进行操作? 我的任务是,要比较两个存放在非本地的(要通过url访问)的文件是否相同。
如果本地文件的话
Set tsa = fso.OpenTextFile("c:\aaa.txt", ForReading)
那如果像这种要通过url访问的呢,我通过
Set tsa = fso.OpenTextFile("http://XXX.XXX.XXX.XXX:10891/SCMWork/RossSCM59Test/aaa.txt
", ForReading) 来访问,访问失败。 http://XXX.XXX.XXX.XXX:10891/SCMWork/RossSCM59Test/aaa.txt 的意思是,如果我在url中手工输入它的话可以在ie上打开该文件。作者: jackymail 时间: 2007-8-3 17:22
下面是我写的一个函数,你拿去参考吧,如果不会就不用再问了,函数里面该有的提示都有了,这个对象叫xmlhttp,你可以上网找个教程看看他的方法。
Private Function check(url)
Set xmlhttp_obj = createobject("microsoft.xmlhttp")
xmlhttp_obj.open "get",url,False
xmlhttp_obj.send
MsgBox xmlhttp_obj.readystate &xmlhttp_obj.status
If xmlhttp_obj.readystate <> 4 Then
MsgBox xmlhttp_obj.readstate
Else
If xmlhttp_obj.status>=200 And xmlhttp_obj.status<300 Then
Stream.writeline url&" valided"
content=xmlhttp_obj.responsetext
'MsgBox content
Set re = New RegExp
re.Pattern = "<A HREF\=\D?(\/[a-z]+)+"
re.Global = True
re.IgnoreCase = True
Set matches = re.execute(content)
For each match in matches
cutstring=Right(match,match.length-13)
newurl=url&cutstring
MsgBox Newurl
check Newurl
Next
End If
End If
Most likely causes:
You are not connected to the Internet.
The website is encountering problems.
There might be a typing error in the address.
What you can try:
Check your Internet connection. Try visiting another website to make sure you are connected.
Retype the address.
Go back to the previous page.
More information
This problem can be caused by a variety of issues, including:
Internet connectivity has been lost.
The website is temporarily unavailable.
The Domain Name Server (DNS) is not reachable.
The Domain Name Server (DNS) does not have a listing for the website's domain.