在groovy中测试URL [英] Testing URLs in groovy
问题描述
我们如何检查url是否正常工作?
当我们点击一个按钮时,我将从'urls'表中的现有db获取所有的url,并且需要检查哪个url正在
操作中
例如:
http://baldwinfilter.com/ products / start.html - 不工作
http://www.subaru .com / - 运行
以及来自db的许多网址。
我的目标是获取所有网址并检查哪一个
我们需要检查它返回的状态吗?
任何人都可以帮助我给出想法...... $ / b $
预先感谢
sri ...
您可以使用HttpBuilder像这样:
@Grab(group ='org.codehaus.groovy.modules.http-builder',module ='http -builder',version ='0.5.0-RC2')
导入groovyx。 net.http.HTTPBuilder
def url = [
http://baldwinfilter.com/products/start.html,
http://www.subaru。 com /
def up = urls.collect {url - >
尝试{
new HTTPBuilder(url).get(path:''){response - >
response.statusLine.statusCode == 200
}
}
catch(e){false}
}
println up
code>
How can we check whether urls are working or not in groovy?
when we click a button, i will get all the urls from existing db from 'urls' table and need to check which url is working
Ex:
http://baldwinfilter.com/products/start.html - not working
http://www.subaru.com/ - working
and so many urls from db.
My aim is to get all urls and check which one is working and which is not .
do we need to check on the status it returns ??
Can any one help me giving idea ...
thanks in advance sri...
You could use HttpBuilder like so:
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0-RC2' )
import groovyx.net.http.HTTPBuilder
def urls = [
"http://baldwinfilter.com/products/start.html",
"http://www.subaru.com/"
]
def up = urls.collect { url ->
try {
new HTTPBuilder( url ).get( path:'' ) { response ->
response.statusLine.statusCode == 200
}
}
catch( e ) { false }
}
println up
这篇关于在groovy中测试URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!