1

Below is the code that I am using in a .PL file, I feel like the ENV that I create may be the issue here, but if I take that out I get a certificate error. I was wondering is there any fix around the 411 Length required error. I have found people talking about POST methods but, I am not using a POST, any help is appreciated. I got thrown into perl today, and I am trying my best just to get a connection to a web service.

#!perl -w

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


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

This is the new and working Code, I got an Authfail error though which is the next problem I will be working on.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
moutonc
  • 239
  • 2
  • 11
  • What makes you think you aren't using POST? That error makes no sense for a GET (since GET requests have no content). – ikegami Jun 14 '12 at 18:22
  • That language's name is "Perl", not "PERL". It's not an acronym, it's an intentional misspelling of "pearl". – ikegami Jun 14 '12 at 18:23
  • @ikegami I didn't think I was using a POST since I am not grabbing anything, I am just trying to make a connection, do you have a good way to use SOAP:Lite to do so? – moutonc Jun 14 '12 at 18:24
  • Also yes, Noticed the misspell after I hit enter, going to edit, was thinking I was putting POST. – moutonc Jun 14 '12 at 18:25
  • SOAP is an RPC mechanism that uses one of numerous transport layers, but the transport layer is usually HTTP. When SOAP uses HTTP, it (always?) uses POST. // No, I don't feel like digging into SOAP::Lite since I've already found numerous bugs in it. – ikegami Jun 14 '12 at 18:31
  • Okay fair enough, I will go look into some other ways to connect to a web service, thank you for the Tip on SOAP::Lite – moutonc Jun 14 '12 at 18:33
  • @moutonc SOAP::Lite is certainly not one of Perl's bright spots. if you're to use it i highly suggest starting with the smallest and simplest test case possible and build up from there in order to meet your actual requirements. debugging SOAP::Lite can be incredibly painstaking. – shinronin Jun 14 '12 at 19:12
  • @user1215106, The server is reporting that the *client* is not setting the length in the *request*. – ikegami Jun 14 '12 at 19:31
  • @shinronin I was able to do a quick test earlier that was successful, when I hit the WebPage: 'http://www.soaplite.com/Demo' when it connected I had it set to say Hello World, then changing the URL I then received the error. – moutonc Jun 14 '12 at 19:35
  • @moutonc can you edit your post with code that does work vs. what you'd like to work? is the WSDL (service), proxy, etc. you'd like to use publicly available for us to test? – shinronin Jun 14 '12 at 20:01
  • @shinronin I am actually not sure what my proxy should be and no, It is not for public eyes sadly, me and another intern have our Perl guy down here trying to teach us. – moutonc Jun 14 '12 at 20:17
  • Figured out the problem guys, I had the proxy set up incorrectly. – moutonc Jun 15 '12 at 12:25
  • excellent. show us the working code? – shinronin Jun 15 '12 at 19:39
  • @shinronin updated for your viewing pleasure. – moutonc Jun 15 '12 at 19:50
  • @moutonc thanks for the update. despite it's odd name, proxy is often the key to getting SOAP::Lite to work. – shinronin Jun 19 '12 at 13:32
  • Yeah, I was just flip-flopping them around glad that I have it working now. Time to convert it into a .Net Framework.. – moutonc Jun 19 '12 at 13:34
  • Downvoted for changing the question. If you find an answer, post an answer to yourself -- or at worst, edit your question to *also* include the new code. Getting rid of the old code makes your question worthless to the community. – darch Jun 19 '12 at 14:48
  • @darch you are correct, posted the code. – moutonc Jun 19 '12 at 14:57

1 Answers1

0

Darch was correct, here is my fully functional working Code for any future users to look at.

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} );
}
}
moutonc
  • 239
  • 2
  • 11