How to add header,username,password sharepoint webservice using ksoap in android
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]; // 开发者_JS百科 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();
}
}
Don't send null values. Instead, add all the values and then try sending it.
Try to use NtlmTransport
instead of HttpTransportSE
. MayBe it works for you.
精彩评论