如何在Android中使用KSOAP添加标题,用户名,密码的SharePoint Web服务 [英] How to add header,username,password sharepoint webservice using ksoap in android

查看:140
本文介绍了如何在Android中使用KSOAP添加标题,用户名,密码的SharePoint Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个Android应用程序将使用getlistitems(在2010年我使用kso​​ap2-机器人来处理我的SOAP消息SharePoint中lists.amx服务)方法。当我尝试验证我得到一个xmlpullparser例外预计START_TAG ......为什么以下code无法验证到SharePoint服务器?

 私有静态最后弦乐SOAP_ACTION =htt​​p://schemas.microsoft.com/sharepoint/soap/GetListItems;
私有静态最后弦乐METHOD_NAME =GetListItems;
私有静态最后弦乐NAMESPACE =htt​​p://schemas.microsoft.com/sharepoint/soap/;
私有静态最终字符串URL =htt​​p://www.domain.com/tr-TR/_vti_bin/Lists.asmx;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);    TextView的电视=(的TextView)findViewById(R.id.tve);    SoapObject要求=新SoapObject空间(namespace,METHOD_NAME);
    request.addProperty(LISTNAME,哈伯勒);
    request.addProperty(的viewName,NULL);
    request.addProperty(查询,NULL);
    request.addProperty(viewFields,NULL);
    request.addProperty(rowLimit,30);
    request.addProperty(queryOptions,NULL);
    request.addProperty(webID,NULL);
    SoapSerializationEnvelope信封=新SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = TRUE;
    envelope.setOutputSoapObject(请求);

// envelope.headerOut =新元素[1];
// envelope.headerOut [0] = buildAuthHeader();

 字符串认证= android.util.Base64.en codeToString(名为myusername:输入mypassword.getBytes(),android.util.Base64.NO_WRAP);
    清单< HeaderProperty>标题=新的ArrayList< HeaderProperty>();
    headers.add(新HeaderProperty(X-FORMS_BASED_AUTH_ACCEPTED,F+验证));    HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
    androidHttpTransport.debug = TRUE;    尝试{
        androidHttpTransport.call(SOAP_ACTION,信封,头);
        SoapObject响应=(SoapObject)envelope.getResponse();        tv.setText(response.toString());
        Log.e(SONUC,response.toString());    }赶上(例外E1){
        e1.printStackTrace();
    }
}


解决方案

尝试使用 NtlmTransport 而不是 HttpTransportSE 。也许它为你工作。

I am writing an Android application that will use the getlistitems() method of the lists.amx service in sharepoint 2010. I am using ksoap2-android to handle my soap messages. When I try to authenticate I get an xmlpullparser exception expected START_TAG... Why will the following code not authenticate to the sharepoint server?

private static final String SOAP_ACTION = "http://schemas.microsoft.com/sharepoint/soap/GetListItems";
private static final String METHOD_NAME = "GetListItems";
private static final String NAMESPACE = "http://schemas.microsoft.com/sharepoint/soap/";
private static final String URL = "http://www.domain.com/tr-TR/_vti_bin/Lists.asmx";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TextView tv=(TextView)findViewById(R.id.tve);

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);


    request.addProperty("listName", "Haberler");
    request.addProperty("viewName", null);
    request.addProperty("query", null);
    request.addProperty("viewFields", null);
    request.addProperty("rowLimit", "30");
    request.addProperty("queryOptions", null);
    request.addProperty("webID",null);




    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);

// envelope.headerOut=new Element[1]; // envelope.headerOut[0]=buildAuthHeader();

    String authentication = android.util.Base64.encodeToString("myusername:mypassword".getBytes(), android.util.Base64.NO_WRAP);
    List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
    headers.add(new HeaderProperty("X-FORMS_BASED_AUTH_ACCEPTED","f" +authentication));

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;

    try {
        androidHttpTransport.call(SOAP_ACTION, envelope,headers);
        SoapObject response = (SoapObject) envelope.getResponse();

        tv.setText(response.toString());
        Log.e("SONUC",response.toString());

    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

解决方案

Try to use NtlmTransport instead of HttpTransportSE. MayBe it works for you.

这篇关于如何在Android中使用KSOAP添加标题,用户名,密码的SharePoint Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆