如何使用android更新Sharepoint 2010列表项?

时间:2014-11-26 13:57:16

标签: android .net sharepoint sharepoint-2010

我正在为android开发一个sharepoint2010应用程序。我想使用以下代码更新sharepoint 2010 ListItem

private void updateListItem() {

    String serviceUrl = "http://IP_address/_vti_bin/Lists.asmx";
    HttpClient httpclient = new DefaultHttpClient();
    ((AbstractHttpClient) httpclient).getAuthSchemes().register("ntlm",
            new NTLMSchemeFactory());
    NTCredentials creds = new NTCredentials("username", "password", "55",
            "demo");
    ((AbstractHttpClient) httpclient).getCredentialsProvider()
            .setCredentials(AuthScope.ANY, creds);
    try {
        HttpConnectionParams.setConnectionTimeout(httpclient.getParams(),
                120000);

        HttpPost httppost = new HttpPost(serviceUrl);
        StringEntity se;            
        String str1 ="<?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>"
                 + "<UpdateListItems xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">"
                 + "<listName>"
                 + "{DF1398C7-EF73-485E-913E-5F5896D6DF22}"
                 + "</listName>"
                 + "<updates>"
                 + "<Batch OnError='Continue' ListVersion='1'>"
                 + "<Method ID='1' Cmd='New'>"
                 + "<Field Name='Title'>View</Field>"
                 + "<Field Name='Resource'>7;#A Kr Singh</Field>"
                 + "<Field Name='Project'>13;#Microsoft- SharePoint based Employee Portal</Field>"
                 + "<Field Name='Task'>1;#Accounting</Field>"
                 + "<Field Name='Date'>2014-11-21 11:15:50</Field>"
                 + "</Method>"
                 + "</Batch>"
                 + "</updates>"
                 + "</UpdateListItems>"
                 + "</soap:Body>" + "</soap:Envelope>";
        se = new StringEntity(String.format(str1, HTTP.UTF_8));

        se.setContentType("text/xml");
        httppost.setEntity(se);

        HttpResponse httpresponse = httpclient.execute(httppost);
        InputStream in = httpresponse.getEntity().getContent();
        String str = inputStreamToString(in).toString();

        readSoap(str);

    } catch (Exception e) {

        e.printStackTrace();
    }
}

但是收到错误

  

soap:抛出了类型为“Microsoft.SharePoint.SoapServer.SoapServerException”的ServerException。此页面的安全验证无效。在Web浏览器中单击“上一步”,刷新页面,然后再次尝试操作.x8102006d

请给我任何解决方案。
或者给我任何其他方法来使用android更新SharepointListItem

1 个答案:

答案 0 :(得分:1)

嗨,经过一些重新训练,我在请求标题中添加以下操作时找到了解决方案。

httppost.setHeader(&#34;的SOAPAction&#34 ;,                     &#34; http://schemas.microsoft.com/sharepoint/soap/UpdateListItems&#34); 之后工作正常。

相关问题