I have been trying since two days to set basic authentication from my android application to SharePoint 2013. I have used HttpUrlConnection,DefaultHttpClient,Retrofit and Volley but these all are showing Authorization failure error. Which is working fine in iOS application.Below is my Vollery code snippet.
private void sendJsonrequestSignIn(final String userName, final String password) {
StringRequest stringRequest = new StringRequest(Request.Method.GET, "http://192.168.50.31/sites/MobileDev/_vti_bin/listdata.svc/TestData",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("ResponseJson", response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//Log.i("ErrorJson", error.getMessage());
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
String creds = String.format("%s:%s", userName, password);
String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.NO_WRAP);
params.put("Authorization", auth);
params.put("Accept", "application/json;odata=verbose");
return params;
}
};
requestQueue.add(stringRequest);
}