WebUserAgent#
NAME#
Kernel::System::WebUserAgent - a web user agent lib
DESCRIPTION#
All web user agent functions.
PUBLIC INTERFACE#
new()#
create an object
use Kernel::System::WebUserAgent;
my $WebUserAgentObject = Kernel::System::WebUserAgent->new(
Timeout => 15, # optional, timeout
Proxy => 'proxy.example.com', # optional, proxy
);
Request()#
return the content of requested URL.
Simple GET request:
my %Response = $WebUserAgentObject->Request(
URL => 'http://example.com/somedata.xml',
SkipSSLVerification => 1, # (optional)
NoLog => 1, # (optional)
# Returns the response content (if available) if the request was not successful.
# Otherwise only the status will be returned (default behavior).
ReturnResponseContentOnError => 1, # optional
);
Or a POST request; attributes can be a hashref like this:
my %Response = $WebUserAgentObject->Request(
URL => 'http://example.com/someurl',
Type => 'POST',
Data => { Attribute1 => 'Value', Attribute2 => 'Value2' },
SkipSSLVerification => 1, # (optional)
NoLog => 1, # (optional)
# Returns the response content (if available) if the request was not successful.
# Otherwise only the status will be returned (default behavior).
ReturnResponseContentOnError => 1, # optional
);
alternatively, you can use an arrayref like this:
my %Response = $WebUserAgentObject->Request(
URL => 'http://example.com/someurl',
Type => 'POST',
Data => [ Attribute => 'Value', Attribute => 'OtherValue' ],
SkipSSLVerification => 1, # (optional)
NoLog => 1, # (optional)
# Returns the response content (if available) if the request was not successful.
# Otherwise only the status will be returned (default behavior).
ReturnResponseContentOnError => 1, # optional
);
returns
%Response = (
Status => '200 OK', # http status
Content => $ContentRef, # content of requested URL
);
You can even pass some headers
my %Response = $WebUserAgentObject->Request(
URL => 'http://example.com/someurl',
Type => 'POST',
Data => [ Attribute => 'Value', Attribute => 'OtherValue' ],
Header => {
Authorization => 'Basic xxxx',
Content_Type => 'text/json',
},
SkipSSLVerification => 1, # (optional)
NoLog => 1, # (optional)
# Returns the response content (if available) if the request was not successful.
# Otherwise only the status will be returned (default behavior).
ReturnResponseContentOnError => 1, # optional
);
If you need to set credentials
my %Response = $WebUserAgentObject->Request(
URL => 'http://example.com/someurl',
Type => 'POST',
Data => [ Attribute => 'Value', Attribute => 'OtherValue' ],
Credentials => {
User => 'otrs_user',
Password => 'otrs_password',
Realm => 'OTRS Unittests',
Location => 'download.znuny.org:80',
},
SkipSSLVerification => 1, # (optional)
NoLog => 1, # (optional)
# Returns the response content (if available) if the request was not successful.
# Otherwise only the status will be returned (default behavior).
ReturnResponseContentOnError => 1, # optional
);