Я пытаюсь использовать asyn c задачу в android studio, чтобы выполнить php скрипт в той же сети, что и я, и получить результат.
private class HTTPReqTask extends AsyncTask<String, String, String> {
String temp = new String();
@Override
protected String doInBackground(String... strings) {
HttpURLConnection urlConnection = null;
try {
URL url = new URL("PHPSCRIBT" + strings[0]);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
int status = con.getResponseCode();
StringBuilder sb = new StringBuilder();
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
while ((line = br.readLine()) != null) {
sb.append(line);
}
temp = sb.toString();
Log.d("myTag", temp);
con.disconnect();
} catch (Exception e) {
}
return temp;
}
protected void onPostExecute(String temp) {
TextView textView = (TextView) findViewById(R.id.textView5);
try {
String erstezahl = temp.split("\\{")[0];
String jsonstring = temp.substring(temp.indexOf("{") - 1);
JSONObject json = new JSONObject(jsonstring);
int amount = Integer.valueOf(erstezahl);
textView.setText(amount);
} catch (Exception e) {
String error = "ERROR +" + temp + "+" + e.toString();
textView.setText(error);
}
}
}
Моя функция onPostExecute () получает пустую строку в качестве параметра. Поэтому я хочу отладить мою функцию doInBackground. Каков наилучший способ сделать это?