用于发布SOAP的Perl或bash脚本

时间:2016-12-20 08:58:45

标签: bash perl curl soap

我需要创建用于发布SOAP请求的bash或perl脚本。情况是它必须从文件中读取特定的数字(逐行)并将每行的请求发布到文件末尾。所以基本上在request.xml查询文件中我需要替换on标签的值 <ICCID xmlns="">VALUE NEEDS TO BE REPACED HERE</ICCID>

在必须读取值的text.txt文件中,内容如下:

89370010100004370782 89370010164904370786 89370010100004370793 ......等等

我的XML文件:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsk="http://www.mskj.it/xsk">
   <soapenv:Header/>
   <soapenv:Body>
      <xsk:CertChangeStatusRequest id="63791" time="2016-10-21T14:17:47.831Z">
     <ApplicationID>TEST</ApplicationID>
     <ServiceID>TEST</ServiceID>
     <ICCID></ICCID>
     <ChangeStatus>Revoke</ChangeStatus>
     <ReasonCode>0</ReasonCode>
     <Comment>test</Comment>
      </xsk:CertChangeStatusRequest>
   </soapenv:Body>
</soapenv:Envelope>

我想过使用curl发布SOAP。

1 个答案:

答案 0 :(得分:0)

可能是基于此的请求:

use strict;
use warnings;

#File opening Structure and learn make it simplify these lines.
my $queryfile = "request.xml";
open(QRY, $queryfile) || die "Can't open/found: $!\n";
local $/; $_=<QRY>; my $qrytext=$_;
close(QRY);

while(<DATA>)
{
    my $mtch_no = $_;
    $qrytext=~s/(<ICCID xmlns=\"\">)([^<>]*)(<\/ICCID>)/$1$mtch_no$3/g;

    # And delete the value from `text.txt` file
    # You can do your work here (post the request here)
}

open(OUT, ">$queryfile") || die "Can't open/found: $!\n";
print OUT $qrytext;
close(OUT);

__DATA__
89370010100004370782
89370010164904370786
89370010100004370793

还有一种方法可以将文本绑定在一个文件中,而不是模块tie::file,用于I / O的单次拍摄。我希望这会有所帮助。