Authentication error while subscribing to SharePoint WebService using ksoap2 Android

I'm writing an Android application that will use the GetList () method of lists.amx service in SharePoint 2010. I'm using ksoap2 Android to process my soap messages. When I try to authenticate, I get an xmlpullparser exception and expect start_ Tag... Why doesn't the following code authenticate the SharePoint Server?

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

This is transport.requestdump (deleted before '<'): > 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: title / > > V: body >

> GetList xmlns =“ http://schemas.microsoft.com/sharepoint/soap/ ”id =“o0”c:root =“1”>

>Listname I: type = "D: string" > move test list

>/ GetList > > / V: body >

>/ V: envelope >

This is transport.responsedump (deleted before '<': >! 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. Invalid request hostname

> / BODY>

> / HTML>

resolvent:

Maybe try the following:

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

By default, Android Base64 util will add a newline character at the end of the encoding string. This will invalidate the HTTP header and cause an "incorrect request"

Base64.NO_ The wrap flag prevents this and keeps the title clear

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>