Open top menu



Basic Authorization :


You have to Add

{
@Overridepublic Map getHeaders() throws AuthFailureError {
    Map params = new HashMap();
    params.put("Content-Type", "application/json; charset=UTF-8");
    params.put("Authorization", basicAut);
    return params;
}



Please check how to call.

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.mespl.volleywebintegration.MyApplication;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class VolleyResponse {
    private static String BaseUrl = "http://" + "Your IP" + "/LoginApplication/";
    public VolleyInterface anInterface;
    private static  String basicAut="";

    public VolleyResponse(int methodType, String MethodName, JSONObject postParams) {

        JsonObjectRequest request = new JsonObjectRequest(methodType, 
                   BaseUrl + MethodName, postParams, new Response.Listener() {
                    @Override                   
                     public void onResponse(Object response) {
                        anInterface.onResponse(response);
                    }
                },

                new Response.ErrorListener() {
                    @Override                   
                 public void onErrorResponse(VolleyError error) {
                        anInterface.onResponse(error);
                    }
                }) {
@Overridepublic Map getHeaders() throws AuthFailureError {
    Map params = new HashMap();
    params.put("Content-Type", "application/json; charset=UTF-8");
    params.put("Authorization", basicAut);
    return params;
}
         
        };

public static void reStart(){
    String credentials = "Username" + ":" + "Password";
    basicAut="Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
}
}


Tagged

0 comments