0

好的...我正在尝试将 XML 页面发布到战略合作伙伴的站点,以便他们进行一些计算并再次通过 XML 向我返回响应代码。

我正在使用花园品种 PERL,并试图使用 LWP::UserAgent 来做到这一点......如果有更优雅的方式,请指出我的方向。

我可以访问他们的服务器,并取回代码......但它拒绝访问他们的服务器,因为它期望的用户名和密码不正确。实际的 XML 代码中没有指定用户名和密码,它应该作为实际 POST 方法的一部分传递给服务器......但我不知道该怎么做。

合作伙伴给出以下反馈:

用他生成的 xml 和他的用户名/密码组合替换 YOUR_XML_FILE、YOUR_USER 和 YOUR_PASSWORD。这应该从他有他的 perl 脚本的服务器上完成。

wget --no-check-certificate --post-file YOUR_XML_FILE https://previewtest.clverify.com/webservice/exec -O previewsamplerequest.response.xml --http-user=YOUR_USER --http-password=YOUR_PASSWORD

我不知道这应该在哪里生成,或者 LWP::UserAgent 中的选项是什么来指定它们。以前有人做过吗?

这是我的代码:

sub ConsumerInfo {
my $cid = shift;

my $response = undef;
my $sendXML = &Create_ConsumerInfo_Request($cid);
if ($sendXML) {
    &DoXMLUpload($sendXML);

    my $browser = LWP::UserAgent->new(agent => 'perl post');
    $browser->credentials('','','username','p@ssword');
    $response = $browser->request(POST 'https://previewtest.clverify.com/webservice/exec',
        Content_Type => 'text/xml',
        Content => $sendXML);
    print "Content-type:text/html\n\n";
    print $response->error_as_HTML unless $response->is_success;
    print $response->as_string;

} else {
    &ErrorMsg("No XML Code Was Found.");
    exit;   
}
# ===============================================================
# Need to insert parser in here to convert this into an array.
# ===============================================================
return $response;
}
4

1 回答 1

2

WARNING: You provided the real URL and password. Change this ASAP, since everybody can connect to the server of your partner now!!

Imho this can be found in the documentation:

$ua->credentials( $netloc, $realm, $uname, $pass )
Get/set the user name and password to be used for a realm. The $netloc is a string of the form ":". The username and password will only be passed to this server.

The example shows the correct way to authenticate:

$ua->credentials("www.example.com:80", "Some Realm", "foo", "secret");

In your case this would mean:

$browser->credentials('previewtest.clverify.com:443','yourRealm','321321','Eep789SHag@');
于 2012-01-24T17:03:38.593 回答