I have 5 text fields and a button that sends the entered data in a form understandable to the server. The problem is that the data on the server is empty. I do not understand where they went? When you click on the button, execute () occurs; This AsyncTask -

private class AddG extends AsyncTask<Void, Void, Void> { HttpURLConnection conn; BufferedWriter writer; BufferedReader reader; OutputStream output; InputStream input; String data; protected Void doInBackground(Void... params) { try { //Берём данные name_data = name_edit.getText().toString(); login_data = login_edit.getText().toString(); password_data = password_edit.getText().toString(); info_data = info_edit.getText().toString(); adress_data = adress_edit.getText().toString(); //строим отправительные данные String post_url = server_name + "/access/index.php?add"; data = "name=" + name_data + "&adress=" + adress_data + "&password=" + password_data + "&login=" + login_data + "&info=" + info_data; //пичкаем коннект URL url = new URL(post_url); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", "Mozilla/5.0 (compatible)"); conn.setRequestProperty("content-type","application/json; charset=utf-8"); conn.setRequestProperty("content-type","application/x-www-form-urlencoded"); conn.setRequestProperty("content-type","application/form-data"); conn.setRequestProperty("Accept","*/*"); conn.setConnectTimeout(8000); conn.setReadTimeout(8000); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); //создаём туннель к серверу и отправляем данные output = conn.getOutputStream(); writer = new BufferedWriter(new OutputStreamWriter(output, "UTF-8")); writer.write(data); writer.flush(); writer.close(); output.close(); conn.connect(); //открываем туннель для ответа от сервера и пихаем его в result input = conn.getInputStream(); reader = new BufferedReader(new InputStreamReader(input, "UTF-8")); StringBuilder result = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { result.append(line); } } catch (Exception e) { } return null; } } 
  • content-type must be one. in your case it is application/x-www-form-urlencoded . Echoing the installation will most likely replace the first one, but in your case it is incorrect to use either application/form-data or application/json . I do not know, maybe it’s conceived that the flows are closed before conn.connect (), but for me this is very strange. Maybe nothing is in principle sent to the server, since everything is closed before connect? url , maybe the wrong address is obtained. And that the server accepts requests for /access/index.php?add How does the server retrieve data from the request? - Sergey
  • @Sergey, the url is correct, getResponseCode returns 200 and I don’t get confused in the links) I don’t know about the server, it’s a professional. threw me a data layout of the form name = f & adress = h & password = v & login = x & info = q and that's it - Flippy

0