<?xml version="1.0" encoding="windows-1252"?>
<node id="1015678" title="NEED URGENT HELP IMPLEMENTING SOAP LITE" created="2013-01-28 05:45:11" updated="2013-01-28 05:45:11">
<type id="115">
perlquestion</type>
<author id="1015673">
ravi_perlmonks</author>
<data>
<field name="doctext">
&lt;p&gt;
hi guys - i am totally new to perl - have one script to make it work for my project purpose need urgent help - am getting 500 cant locate server_name - any ideas welcome thanks
&lt;/p&gt;
&lt;code&gt;
#!/sbcimp/run/pd/csm/64-bit/perl/5.16.1/bin/perl
use strict;
use warnings;
use lib '/dir.../lib';
use MIME::Base64;
use SOAP::Lite;
use File::MimeInfo;
use File::Basename;
use Data::Dumper;
# the ServiceNow instance
my $SNC_HOST = "https://server_name:16000";
my $base64;
my $buf;
my $mime_type;
my $fname;
print "var initialised\n";
#escape certificate check
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;

my $line = "/file_path..../vdpsloader4.jpg";
# upload and attach a file on the local disk, base 64 encode it into a string first

#while(&lt;FILE&gt;){
#my $line = $_;
#chomp($line);
$mime_type = mimetype($line);
$fname = basename($line);
open(SFILE, $line) or die "$!";
while (read(SFILE, $buf, 60*57)) {
$base64 .= encode_base64($buf);
print "reading file\n";
# call the sub routine to attach
attach_incident();
}
#}
sub attach_incident {
  # target the ecc_queue table
  my $soap = SOAP::Lite-&gt;proxy("$SNC_HOST/ecc_queue.do?SOAP");
  my $method = SOAP::Data-&gt;name('insert')-&gt;attr({xmlns =&gt; 'http://www.service-now.com/'});
  # set the ecc_queue parameters
  my @params = (SOAP::Data-&gt;name(agent =&gt; 'AttachmentCreator'));
  push(@params, SOAP::Data-&gt;name(topic =&gt; 'AttachmentCreator') );
  # identify the file name and its mime type
  push(@params, SOAP::Data-&gt;name(name =&gt; '$fname:application/$mime_type') );
  # attach to the incident, specifying its sys_id
  push(@params, SOAP::Data-&gt;name(source =&gt; 'incident:uniqueID') );
  # set the payload to be the base 64 encoded string representation of the file
  push(@params, SOAP::Data-&gt;name(payload =&gt; $base64) );
  print "before WS invoke\n";
  # invoke the web service
  print "++++++++++++\n"
  print "@params"
  my $result = $soap-&gt;call($method =&gt; @params);
  print Dumper($result);
print "after WS invoke\n";
  print_fault($result);
  print_result($result);
}
sub print_result {
  my ($result) = @_;
  if ($result-&gt;body &amp;&amp; $result-&gt;body-&gt;{'insertResponse'}) {
    my %keyHash = %{ $result-&gt;body-&gt;{'insertResponse'} };
    foreach my $k (keys %keyHash) {
        print "name=$k   value=$keyHash{$k}\n";
    }
  }
}
sub print_fault {
  my ($result) = @_;
  if ($result-&gt;fault) {
    print "faultcode=" . $result-&gt;fault-&gt;{'faultcode'} . "\n";
    print "faultstring=" . $result-&gt;fault-&gt;{'faultstring'} . "\n";
    print "detail=" . $result-&gt;fault-&gt;{'detail'} . "\n";
  }
}
# use the itil user for basic auth credentials
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
   return 'user_name' =&gt; 'pswd';
}


&lt;/code&gt;</field>
</data>
</node>
