Basic authentication does not work with Android until Sharepoint 2013

I’m trying from two days to establish basic authentication from my Android application in SharePoint 2013. I used HttpUrlConnection, DefaultHttpClient, Retrofit and Volley, but they all show an authorization failure error. Which works great in an iOS app. This 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); } 
+6
source share
3 answers

Have you tried Jshare . This library supports NTLM and works with Java and Android. I think this may help with NTLM authentication in your application.

+1
source

You can use Authenticator for basic-auth.

 import java.net.Authenticator; import java.net.HttpURLConnection; import java.net.PasswordAuthentication; import java.net.URL; try { Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("user", "password".toCharArray()); } }); URL url = new URL(DOWNLOAD_URL); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setReadTimeout(10000); con.setConnectTimeout(15000); con.setRequestMethod("GET"); con.setUseCaches(false); con.connect(); 
+1
source

I ran into this problem before and I fixed it.

Do not use

Basic authentication

Using

NTLM Authentication

I just added meaning to this: https://gist.github.com/franciscerio/4b0a6a969eda3b93098a50174cffd8de#file-gistfile2-txt .

I forgot the source that helped me. I hope you understand.:)

0
source

All Articles