[英]Make soap client python with suds
I create this script in perl: 我在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;
}
Now I intend to do the same in python, I looked some components and found suds, but was unable to write something as simple as perl, did not yet have much experience with python, can you help me? 现在我打算在python中做同样的事情,我查看了一些组件并找到了suds,但是无法编写像perl这样的简单内容,还没有python的丰富经验,您能帮我吗?
I created sample scripts with suds, pysimplesoap, but they did not work as I would like, so I made something using urllib2 and it worked perfectly. 我用suds,pysimplesoap创建了示例脚本,但是它们并没有按照我的意愿工作,因此我使用urllib2进行了一些操作,并且效果很好。 I have problems because the url of my API is http://xxxxxx.com:8080/action.asmx and the httplib does not work.
我遇到了问题,因为我的API的网址是http://xxxxxx.com:8080/action.asmx ,而httplib无法正常工作。
Anyway thanks for answer. 无论如何,谢谢您的回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.