Я продолжаю получать внутреннюю ошибку сервера 500 для этого кода. Я использую веб-API Rest.Когда я запускаю программу, она работает, но не передает никаких данных в API.Ответ, который я получаю при запуске отладчика: Response{protocol=http/1.1, code=500, message=Internal Server Error, url=http://192.168.1.250:5001/api/v1/job}
Данные теста JSON, которые я получаю: {"id":"103","customer":{"id":31,"name":"ABC Poland"},"stops":{"Address":{"contact":{"name":"Play"}}},"references":{},"instructions":{"Value":"char"},"loads":{}}
Вот полный код класса AsyncTask, у меня есть больше кода, но я думаю,было бы бессмысленно добавлять его, и вам, ребята, было бы труднее помочь мне:
public class myNetworkTask extends AsyncTask<Void, Void, Void> {
private ProgressBar progressBar;
protected Void doInBackground(Void... params) {
DBHandler db = new DBHandler(getApplicationContext());
int jobNoParam = jdb.getNextJobNo() - 1;
try {
URL url = new URL("http://192.168.1.250:5001/api/v1/job");
js.put("id", String.valueOf(jobNoParam));
JSONObject customerJSON = new JSONObject();
JSONObject stopsJson = new JSONObject();
JSONObject contactNameJson = new JSONObject();
JSONObject referencesJson = new JSONObject();
JSONObject instructionsJson = new JSONObject();
JSONObject addressJson = new JSONObject();
JSONObject loadsJson = new JSONObject();
if (jdb.getCustomerName(jobNoParam) != null && !jdb.getCustomerName(jobNoParam).equals("")) {
String idParam = jdb.getCustomerName(jobNoParam);
int id = db.getCompanyId(idParam);
customerJSON.put("id", id);
customerJSON.put("name", jdb.getCustomerName(jobNoParam) );
}
Log.i("sendDataToServer", "First if!");
if (jdb.getContactName(jobNoParam) != null && !jdb.getContactName(jobNoParam).equals("")) {
contactNameJson.put("name", jdb.getContactName(jobNoParam));
}
Log.i("sendDataToServer", "Second if!");
if (jdb.getJobType(jobNoParam) != null && jdb.getJobType(jobNoParam).equals("")) {
instructionsJson.put("Title", jdb.getJobType(jobNoParam));
}
Log.i("sendDataToServer", "Third if!");
if (jdb.getIssue(jobNoParam) != null && !jdb.getIssue(jobNoParam).equals("")) {
instructionsJson.put("Value", jdb.getIssue(jobNoParam));
}
// Log.i("sendDataToServer", "Fourth if!");
// js.put("Customer Name:", String.valueOf(customerJSON));
js.put("customer", customerJSON);
addressJson.put("contact", contactNameJson);
stopsJson.put("Address", addressJson);
js.put("stops", stopsJson);
js.put("references", referencesJson);
js.put("instructions", instructionsJson);
js.put("loads", loadsJson);
json = js.toString();
//Toast.makeText(getApplicationContext(), "Connected Successfully",
//Toast.LENGTH_LONG).show();
doPostRequest(url, json);
}
catch (MalformedURLException | JSONException e) {
e.printStackTrace();
}
return null;
}
protected Void onPostExecute () {
return null;
}
public void doPostRequest (URL url,final String json){
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new HttpLoggingInterceptor())
.build();
String credential = okhttp3.Credentials.basic(/*username*/, /*password */);
final RequestBody body = RequestBody.create(JSON, js.toString());
Request request = new Request.Builder()
.addHeader("Accept", "application/json")
.addHeader("Authorization", credential)
.url(url)
.post(body)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.d("TAG ------->", "Call Cancelled");
call.cancel();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
Log.d("TAG --------> onResponse:", response.body().string());
Log.d("JSON TAG ---------->", json);
Log.d("TAG Response Message ------>", response.message());
}
});
}
}