I am trying to log into server to receive a json file back. But the server needs a useame and pass word. I don't know how to add that into my build. I looked at a lot of sources but I caot figure it out what to add to my builder. Thank you very much for any help
Here is my OkhttpHandeler code
public class OkHttpHandler extends AsyncTask<String, Void, String> {
OkHttpClient client = new OkHttpClient();
Response response;
Request request;
private final String apUrl = "http://xxxxxxxx.xxxxxx.com/api/1.0/promotions";
String output;
String picture;
//JSon Data
String jsonData;
JSONObject jsonObject;
JSONArray jsonArray;
@Override
protected String doInBackground(String... params) {
RequestBody formbody = new FormBody.Builder()
.add("useame", "admin")
.add("password", "admin")
.build();
//Request.Builder builder = new Request.Builder();
//builder.url(params[0]);
request = new Request.Builder()
.url(apUrl)
.post(formbody)
.build();
//request = builder.build();
try {
response = client.newCall(request).execute();
Log.d("Respones:", response.body().string());
output = response.body().string();
jsonData = output;
try {
jsonObject = new JSONObject(jsonData);
jsonArray = jsonObject.getJSONArray("");
} catch (JSONException e) {
e.printStackTrace();
}
try {
JSONObject object = jsonArray.getJSONObject(0);
picture = object.getString("picture");
} catch (JSONException e) {
e.printStackTrace();
}
//retu response.body().bytes();
retu picture;
}catch (Exception e){
e.printStackTrace();
}
retu null;
}
}
