(2014年5月19日更新)
我尝试使用SOAP :: Lite编写Perl脚本以将新项添加到Sharepoint列表 使用UpdateListItems方法。
我没有太多使用SOAP的经验,因此我一直在使用这些来源编写代码:
http://www.squish.net/log/2008/10/11/perl-sharepoint/
http://msdn.microsoft.com/en-us/library/lists.lists.updatelistitems.aspx
我尝试直接从squish.net页面复制,但是当它没有成功时,我使用SOAP :: Data文档重写了一些。这是我到目前为止所做的,只是尝试创建一个带有标题和注释的列表项,因为这些是必填字段。 (我查了一下,这些是字段的正确内部名称)
use LWP::UserAgent;
use LWP::Debug;
use LWP::Authen::Ntlm;
use SOAP::Lite +trace => [ transport => sub { print $_[0]->as_string }, 'debug' ];
import SOAP::Data;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
our $sp_endpoint = 'https://sharepoint.<DOMAIN>.com/';
our $sp_domain = 'sharepoint.<DOMAIN>.com:443';
our $sp_username = '<USERNAME>';
our $sp_password = '<PASSWORD>';
my @ua_args = (keep_alive => 1);
my @credentials = ($sp_domain, "", $sp_username, $sp_password);
my $schema_ua = LWP::UserAgent->new(@ua_args);
$schema_ua->credentials(@credentials);
$soap = SOAP::Lite->proxy($sp_endpoint, @ua_args, credentials => \@credentials);
$soap->schema->useragent($schema_ua);
$soap->uri("http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
my $title = SOAP::Data->name('Field')->value('test title')->attr({'Name' => 'Title'});
my $comment = SOAP::Data->name('Field')->value('test comment')->attr({'Name' => 'Comment'});
my @fields = ($title, $comment);
my $method = SOAP::Data->name('Method')->value(\@fields)->attr({'ID' => '1', 'Cmd' => 'New'});
my $batch = SOAP::Data->name('Batch')->value(\$method)->attr({'OnError' => 'Continue', 'ListVersion' => '1'});
my $in_updates = SOAP::Data->name('updates')->value(\$batch);
my $lists = $soap->UpdateListItems($in_listName, $in_updates);
quit(1, $lists->faultstring()) if defined $lists->fault();
我将PERL_LWP_SSL_VERIFY_HOSTNAME
设置为0,因为我无法使证书身份验证正常工作,至少目前这似乎是一个很好的解决方案。
运行它给了我这个回复:
POST https://sharepoint.<DOMAIN>.com/ HTTP/1.1
Accept: text/xml
Accept: multipart/*
Accept: application/soap
Content-Length: 838
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems#UpdateListItems"
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body>
<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/UpdateListItems">
<listName xsi:type="xsd:string">{2CC9AAAA-4884-4331-B7C9-E724A92BBFC2}</listName>
<updates>
<Batch ListVersion="1" OnError="Continue">
<Method Cmd="New" ID="1" soapenc:arrayType="xsd:string[2]" xsi:type="soapenc:Array">
<Field Name="Title" xsi:type="xsd:string">test title</Field>
<Field Name="Comment" xsi:type="xsd:string">test comment</Field>
</Method></Batch>
</updates>
</UpdateListItems>
</soap:Body></soap:Envelope>
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Date: Mon, 19 May 2014 20:48:59 GMT
Server: Microsoft-IIS/7.5
Vary: Accept-Encoding
Content-Length: 48464
Content-Type: text/html; charset=utf-8
Expires: Sun, 04 May 2014 20:48:59 GMT
Last-Modified: Mon, 19 May 2014 20:48:59 GMT
Client-Date: Mon, 19 May 2014 20:49:00 GMT
Client-Peer: 10.9.154.101:443
Client-Response-Num: 6
Client-SSL-Cert-Issuer: /C=US/O=*** Corporation/CN=*** Intranet Basic Issuing CA 2A
Client-SSL-Cert-Subject: /CN=sharepoint.<DOMAIN>.com
Client-SSL-Cipher: RC4-SHA
Client-SSL-Socket-Class: IO::Socket::SSL
Client-SSL-Warning: Peer certificate not verified
Link: </Style%20Library/en-US/Themable/Core%20Styles/controls.css>; rel="stylesheet"; type="text/css"
Link: </_layouts/1033/styles/layouts.css>; rel="stylesheet"; type="text/css"
Link: </Style%20Library/en-US/Core%20Styles/page-layouts-21.css>; rel="stylesheet"; type="text/css"
Link: </_layouts/1033/styles/Themable/search.css?rev=T%2Bhraxktc1A8EnaG5gGMHQ%3D%3D>; rel="stylesheet"; type="text/css"
Link: </_layouts/1033/styles/Themable/corev4.css?rev=p63%2BuzTeSJc22nVGNZ5zwg%3D%3D>; rel="stylesheet"; type="text/css"
Link: </_vti_bin/spsdisco.aspx>; rel="alternate"; type="text/xml"
Link: </_layouts/images/favicon.ico>; rel="shortcut icon"; type="image/vnd.microsoft.icon"
MicrosoftSharePointTeamServices: 14.0.0.7108
Persistent-Auth: true
SPRequestGuid: c40f028a-bb5b-4f38-87d9-5ca7ff80d899
Title: home
X-AspNet-Version: 2.0.50727
X-Meta-GENERATOR: Microsoft SharePoint
X-Meta-Progid: SharePoint.WebPartPage.Document
X-MS-InvokeApp: 1; RequireReadOnly
X-Powered-By: ASP.NET
X-SharePointHealthScore: 2
X-UA-Compatible: IE=8
然后它打印出$sp_endpoint
变量中指定的页面的html源。
似乎没有任何错误,但它并没有向列表中添加任何内容。我为$sp_endpoint
尝试了几个不同的值,因为我不确定它是应该是列表本身的页面还是仅仅是根目录,但我尝试过的所有内容都是无法真正更新列表。任何有助于修复或诊断问题的提示都将不胜感激。谢谢!
答案 0 :(得分:0)
修正了它。这里有一些实际有用的代码:
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
use LWP::UserAgent;
use LWP::Debug;
use LWP::Authen::Ntlm;
use Authen::NTLM;
use SOAP::Lite;
import SOAP::Data;
use Data::Dumper;
ntlmv2(1);
our $sp_endpoint = 'https://sharepoint.<DOMAIN>.com/sites/<PATH>/_vti_bin/Lists.asmx';
our $sp_domain = 'sharepoint.<DOMAIN>.com:443';
our $sp_username = '\\<USERNAME>';
our $sp_password = '<PASSWORD>';
our @ua_args = (keep_alive => 1);
our @credentials = ($sp_domain, '', $sp_username, $sp_password);
our $schema_ua = LWP::UserAgent->new(@ua_args);
$schema_ua->credentials(@credentials);
our $soap = SOAP::Lite->proxy($sp_endpoint, @ua_args, credentials => \@credentials)->default_ns('http://schemas.microsoft.com/sharepoint/soap/')->on_action(sub { $_[0].$_[1] });
$soap->schema->useragent($schema_ua);
our $in_listName = SOAP::Data->name('listName')->value('{2CC9AAAA-4884-4331-B7C9-E724A92BBFC2}');
our $titleField = SOAP::Data->name('Field')->value('test title')->attr({'Name' => 'Title'});
our $commentField = SOAP::Data->name('Field')->value('test comment')->attr({'Name' => 'Comment'});
our @fields = ($titleField, $commentField);
our $method = SOAP::Data->name('Method')->value(\@fields)->attr({'ID' => '1', 'Cmd' => 'New'});
our $batch = SOAP::Data->name('Batch')->value(\$method)->attr({'OnError' => 'Return', 'ListVersion' => '1'});
our $in_updates = SOAP::Data->name('updates')->value(\$batch);
$soap->UpdateListItems($in_listName, $in_updates);
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=1;