如何在android中使用kso​​ap添加标头、用户名、密码共享点Web服务

发布于 2024-11-24 20:49:16 字数 2082 浏览 2 评论 0原文

我正在编写一个Android应用程序,它将使用sharepoint 2010中lists.amx服务的getlistitems()方法。我正在使用kso​​ap2-android来处理我的soap消息。当我尝试进行身份验证时,出现预期的 xmlpullparser 异常 START_TAG... 为什么以下代码无法对共享点服务器进行身份验证?

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);

// 信封.headerOut=新元素[1]; // 信封.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();
    }
}

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();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

落花随流水 2024-12-01 20:49:16

不要发送空值。相反,添加所有值,然后尝试发送。

Don't send null values. Instead, add all the values and then try sending it.

醉南桥 2024-12-01 20:49:16

尝试使用 NtlmTransport 而不是 HttpTransportSE。也许它适合你。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文