用suds制作soap客户端python

2024-05-16 02:49:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我用perl创建这个脚本:

#!"c:\strawberry\perl\bin\perl.exe"

use strict;

use LWP::UserAgent;
use HTTP::Request;

my $message = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <AddUser xmlns="http://tempuri.org/">
      <HostUserName>hcadmin</HostUserName>
      <HostPassword>XXXXXXXXX</HostPassword>
      <OwnerName>hcadmin</OwnerName>
      <PlanName>Unlimited Plan - Windows</PlanName>
      <NewUserName>froyland</NewUserName>
      <NewUserPassword>XXXXXXX</NewUserPassword>
      <EmailAddress>john@hosting.net</EmailAddress>
      <ResellerType>Dedicated</ResellerType>
      </AddUser>
  </soap:Body>
</soap:Envelope>';
my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(POST => 'http://painel.a.nrserver.net:8080/UserManager.asmx');
$request->header(SOAPAction => '"http://tempuri.org/AddUser"');
$request->content($message);
$request->content_type("text/xml; charset=utf-8");
my $response = $userAgent->request($request);

if($response->code == 200) {
    print $response->as_string, '\n';
}
else {
    print $response->error_as_HTML;
}

现在我打算用python做同样的事情,我看了一些组件,找到了sud,但是不能写像perl这样简单的东西,还没有太多的python经验,你能帮我吗?在


Tags: orghttpmessageuseresponserequestmysoap