[英]Make soap client python with suds
我在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中做同樣的事情,我查看了一些組件並找到了suds,但是無法編寫像perl這樣的簡單內容,還沒有python的豐富經驗,您能幫我嗎?
我用suds,pysimplesoap創建了示例腳本,但是它們並沒有按照我的意願工作,因此我使用urllib2進行了一些操作,並且效果很好。 我遇到了問題,因為我的API的網址是http://xxxxxx.com:8080/action.asmx ,而httplib無法正常工作。
無論如何,謝謝您的回答。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.