There is a URL to get the data: http://ps1722.weeteam.net/api/products?display=[name,desc, id_default_image,price,reference_&limit=20

Authorization - Basic:

login: XHKM6A6BLCA5MNYZQBX2GXBAAKSTPMK2

password: no password

Basic encoding method:

public static String getAuthToken() { byte[] data = new byte[0]; try { data = ("login" + ":" + "password").getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return "Basic " + Base64.encodeToString(data, Base64.NO_WRAP); } 

How to get data by reference.

I use Retrofit2:

 public interface APIService { @GET("api/productsdisplay=[name,description,id_default_image,price,reference]&limit=20") Call<ResponseBody> callBack (@Header("Authorization") String credential); } 

    2 answers 2

    Retrofit uses OkHttp as an http client. For Basic Authorization, you only need this code:

     OkHttpClient okHttpClient = new OkHttpClient.Builder() .authenticator((route, response) -> { Request request = response.request(); if (request.header("Authorization") != null) // Логин и пароль неверны return null; return request.newBuilder() .header("Authorization", Credentials.basic("login", "password")) .build(); }) .build(); Retrofit retrofit = new Retrofit.Builder() .client(okHttpClient) ... .build(); 

    Please note that in this code you can only use a pre-wired login / password pair, if you need support for different ones, you should create a separate class implementing the Authenticator

      You need to add the header - Authorization: Basic XHKM6A6BLCA5MNYZQBX2GXBAAKSTPMK2 when prompted, I cannot say exactly how to insert it in your case, I don’t know which client you are using.

      • I use Retrofit2: public interface APIService {@GET ("api / productsdisplay = [name, description, id_default_image, price, reference] & limit = 20") Call <ResponseBody> callBack (@Header ("Authorization") String credential); } - Ruslan Chepizhko
      • RequestInterceptor should be used to inject the token into the header - docks - Ruslan Yagupov