错误411长度不需要POST

时间:2012-06-14 18:18:21

标签: perl soap soaplite

下面是我在.PL文件中使用的代码,我觉得我创建的ENV可能是这里的问题,但如果我把它拿出来我会得到证书错误。我想知道是否有任何修复411长度所需的错误。我发现有人在谈论POST方法但是,我没有使用POST,任何帮助都表示赞赏。我今天被扔进了perl,我正在努力获得与Web服务的连接。

#!perl -w

use SOAP::Lite;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;


use Data::Dumper;
print Dumper(SOAP::Lite
-> proxy('mywebsite')
-> GetTicket()
-> result);

这是新的工作代码,我收到了一个Authfail错误,但这是我将要处理的下一个问题。

1 个答案:

答案 0 :(得分:0)

Darch是正确的,这是我的全功能工作代码,供任何未来的用户查看。

use strict;
use warnings;

# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);

use SOAP::Lite;
use Data::Dumper;

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;

my $URL = 'myURL';

my $NameSpace = 'myNameSpace';

# this is operation to execute, it could be TicketCreate, TicketUpdate, TicketGet, TicketSearch
# or SessionCreate. and they must to be defined in the web service.
my $Operation = 'GetTicket';

# this variable is used to store all the parameters to be included on a request in XML format, each
# operation has a determined set of mandatory and non mandatory parameters to work correctly, please
# check OTRS Admin Manual in order to get the complete list.
my $XMLData = '
<UserLogin>myUser</UserLogin>
<Password>myPassword</Password>
    <TicketID>1</TicketID>


';

# ---

# create a SOAP::Lite data structure from the provided XML data structure.
my $SOAPData = SOAP::Data
->type( 'xml' => $XMLData );

my $SOAPObject = SOAP::Lite
->uri($NameSpace)
->proxy($URL)
->$Operation($SOAPData);

# check for a fault in the soap code.
if ( $SOAPObject->fault ) {
print $SOAPObject->faultcode, " ", $SOAPObject->faultstring, "\n";
}

# otherwise print the results.
else {

# get the XML response part from the SOAP message.
my $XMLResponse = $SOAPObject->context()->transport()->proxy()->http_response()->content();

# deserialize response (convert it into a perl structure).
my $Deserialized = eval {
    SOAP::Deserializer->deserialize($XMLResponse);
};

# remove all the headers and other not needed parts of the SOAP message.
my $Body = $Deserialized->body();

# just output relevant data and no the operation name key (like TicketCreateResponse).
for my $ResponseKey ( keys %{$Body} ) {
    print Dumper( $Body->{$ResponseKey} );
}
}