使用kso​​ap2-机器人订阅到SharePoint Web服务时的错误身份验证

使用kso​​ap2-机器人订阅到SharePoint Web服务时的错误身份验证

问题描述:

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

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?

下面是我的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();
    }
}
}

下面是transport.requestdump(preceeding'&LT;'去掉):

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


  • 五:信封的xmlns:I =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:D =htt​​p://www.w3.org/2001/XMLSchema中的xmlns:C = http://schemas.xmlsoap.org/soap/encoding/的xmlns:v =htt​​p://schemas.xmlsoap.org/soap/envelope/>

    • 五:页眉/>

    • 五:车身>

      • 的GetList的xmlns =htt​​p://schemas.microsoft.com/sharepoint/soap/ID =O0C:根=1>

        • LISTNAME我:TYPE =D:字符串>移动测试列表

        下面是transport.responsedump(preceeding'&LT;'去掉):

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


        • DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.01 // ENhttp://www.w3.org/TR/html4/strict.dtd>

          • HTML>

          • HEAD>

            • TITLE>错误请求

            • META HTTP-EQUIV =Content-Type的CONTENT =text / html的;字符集= US-ASCII>


            • H2>错误的请求 - 无效的主机名

            • HR> P> HTTP错误400请求主机名无效。
            • h2>Bad Request - Invalid Hostname
            • hr> p>HTTP Error 400. The request hostname is invalid.

也许尝试以下操作:

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

默认情况下,Android版的Base64 UTIL增加了一个换行符的EN codeD字符串的结尾。这种无效的HTTP头和导致错误的请求。

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".

Base64.NO_WRAP 标志prevents这一点,并保持头在机智。

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