简体   繁体   English

如何通过Perl脚本向Weblogc服务器发送HTTP请求

[英]how to send http request through perl script to weblogc server

There is a requirement to check the status of the webservice running on weblogic. 需要检查在weblogic上运行的Web服务的状态。 The web service runs in the background and doesnt have HTML page to laucch though browsers. 该Web服务在后台运行,没有HTML页面可通过浏览器访问。 However it responds to HTTP queries along with the request type. 但是,它会响应HTTP查询以及请求类型。

I need to send the request say and it responds with the corrosponding status code. 我需要发送要求说,它以相应的状态代码响应。 The problem is there is no frame or web page to type the request. 问题是没有框架或网页可以键入请求。 The request has to be sent programmatically. 该请求必须以编程方式发送。 Can this be done using perl? 可以使用perl完成吗?

I tried using LWP module but couldnt get the desired results, 我尝试使用LWP模块,但无法获得理想的结果,

#!/usr/bin/perl
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$PARAM = "<HealthCheck>" ;

my $req = (POST '[http://host_name:8080/service]' ["xmlString" => $PARAM]);
$request = $ua->request($req); 
$content = $request->content; 

print $content; 
exit; 

Please help. 请帮忙。

Regards... 问候...

Sure, it's possible, just change the syntax: 当然,可以更改语法:

#!/usr/bin/perl
use strict;
use warnings;

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
my $PARAM = "<HealthCheck>" ;

my $response = $ua->post('http://host_name:8080/service', {'xmlString' => $PARAM}); 
if( $response->is_success ) {
   print $response->decoded_content;
}
else {
   print STDERR $response->status_line, "\n";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM