使用 ksoap2-android 订阅共享点 Web 服务时出现身份验证错误

发布于 2024-11-07 06:56:37 字数 3321 浏览 4 评论 0原文

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

这是我的代码:

public class SharepointList extends Activity {
private static final String SOAP_ACTION = "http://schemas.microsoft.com/sharepoint/soap/GetList";
private static final String METHOD_NAME = "GetList";
private static final String NAMESPACE = "http://schemas.microsoft.com/sharepoint/soap/" ;
private static final String URL = "http://<ip of sharepoint server>/_vti_bin/lists.asmx";

private TextView result;
private Button btnSubmit;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    result = (TextView)findViewById(R.id.textView1);
    btnSubmit = (Button)findViewById(R.id.button1);
    btnSubmit.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
            if(v.getId() == R.id.button1)
            {
                String list = getMobileTestList();
                result.setText(list);
            }

        }

    });


}
private String getMobileTestList()
{
    PropertyInfo pi = new PropertyInfo();
    pi.setName("listName");
    pi.setValue("Mobile Test List");

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty(pi);

    String authentication = android.util.Base64.encodeToString("username:password".getBytes(), android.util.Base64.DEFAULT);
    List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
    headers.add(new HeaderProperty("Authorization","Basic " +authentication));
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);


    HttpTransportSE transport = new HttpTransportSE(URL);
    try
    {
        transport.debug = true;
        transport.call(SOAP_ACTION, envelope, headers);
        //transport.call(SOAP_ACTION, envelope);
        Object result = envelope.getResponse();
        return result.toString();

    }
    catch(Exception e)
    {
        return e.toString();
    }
}
}

这是 Transport.requestdump (前面的 '<' 已删除):

  • v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http ://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
    • v:标题/>
    • v:主体>
      • GetList xmlns="http://schemas.microsoft.com/sharepoint/soap/" id="o0" c:root="1">
        • listName i:type="d:string">移动测试列表
    • /GetList>
    • /v:正文>
  • /v:信封>

以下是 Transport.responsedump(删除了前面的“<”):

  • !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict。 dtd”>
    • HTML>
    • 头>
      • TITLE>错误请求
      • META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">
    • /HEAD>
    • 身体>
      • h2>错误请求 - 无效主机名
      • 小时> p>HTTP 错误 400。请求主机名无效。

    • /身体>
  • /HTML>

I am writing an Android application that will use the getlist() 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?

Here is my code:

public class SharepointList extends Activity {
private static final String SOAP_ACTION = "http://schemas.microsoft.com/sharepoint/soap/GetList";
private static final String METHOD_NAME = "GetList";
private static final String NAMESPACE = "http://schemas.microsoft.com/sharepoint/soap/" ;
private static final String URL = "http://<ip of sharepoint server>/_vti_bin/lists.asmx";

private TextView result;
private Button btnSubmit;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    result = (TextView)findViewById(R.id.textView1);
    btnSubmit = (Button)findViewById(R.id.button1);
    btnSubmit.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
            if(v.getId() == R.id.button1)
            {
                String list = getMobileTestList();
                result.setText(list);
            }

        }

    });


}
private String getMobileTestList()
{
    PropertyInfo pi = new PropertyInfo();
    pi.setName("listName");
    pi.setValue("Mobile Test List");

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty(pi);

    String authentication = android.util.Base64.encodeToString("username:password".getBytes(), android.util.Base64.DEFAULT);
    List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
    headers.add(new HeaderProperty("Authorization","Basic " +authentication));
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);


    HttpTransportSE transport = new HttpTransportSE(URL);
    try
    {
        transport.debug = true;
        transport.call(SOAP_ACTION, envelope, headers);
        //transport.call(SOAP_ACTION, envelope);
        Object result = envelope.getResponse();
        return result.toString();

    }
    catch(Exception e)
    {
        return e.toString();
    }
}
}

Here is the transport.requestdump (preceeding '<' removed):

  • v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
    • v:Header />
    • v:Body>
      • GetList xmlns="http://schemas.microsoft.com/sharepoint/soap/" id="o0" c:root="1">
        • listName i:type="d:string">Mobile Test List
    • /GetList>
    • /v:Body>
  • /v:Envelope>

Here is the transport.responsedump (preceeding '<' removed):

  • !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
    • HTML>
    • HEAD>
      • TITLE>Bad Request
      • META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">
    • /HEAD>
    • BODY>
      • h2>Bad Request - Invalid Hostname
      • hr> p>HTTP Error 400. The request hostname is invalid.

    • /BODY>
  • /HTML>

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

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

发布评论

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

评论(1

So要识趣 2024-11-14 06:56:37

也许可以尝试以下操作:

String authentication = android.util.Base64.encodeToString("username:password".getBytes(), android.util.Base64.NO_WRAP);

默认情况下,Android Base64 util 将换行符添加到编码字符串的末尾。这会使 HTTP 标头无效并导致“错误请求”。

Base64.NO_WRAP 标志可以防止这种情况发生并保持标头完好无损。

Maybe try the following:

String authentication = android.util.Base64.encodeToString("username:password".getBytes(), android.util.Base64.NO_WRAP);

By default the Android Base64 util adds a newline character to the end of the encoded string. This invalidates the HTTP headers and causes the "Bad request".

The Base64.NO_WRAP flag prevents this and keeps the headers in tact.

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