RosettaCodeData/Task/HTTP/Sidef/http.sidef

14 lines
346 B
Text
Raw Permalink Normal View History

2016-12-05 23:44:36 +01:00
func get(url) {
var lwp = (
try { require('LWP::UserAgent') }
2017-09-23 10:01:46 +02:00
catch { warn "'LWP::UserAgent' is not installed!"; return nil }
)
var ua = lwp.new(agent => 'Mozilla/5.0')
2016-12-05 23:44:36 +01:00
if (var resp = ua.get(url); resp.is_success) {
2017-09-23 10:01:46 +02:00
return resp.decoded_content
}
return nil
2016-12-05 23:44:36 +01:00
}
2017-09-23 10:01:46 +02:00
print get("http://rosettacode.org")