5 EditText and button that sends the entered data. I try to send using the POST method, but apparently, something is not being performed somewhere. I can not track the code in any way, I program from the phone. I bring the array in toast. There are no problems with the collection of information. The point is to send. Help me to understand. Code:
public class AddRegisterActivity extends Activity { String server_name = "http://dev.pareto-marketing.ru"; String name_data, adress_data, login_data, password_data, info_data; EditText name_edit, adress_edit, password_edit, login_edit, info_edit; Button btn_add; AddG add_to; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.addregxml); name_edit = (EditText)findViewById(R.id.name_edit); adress_edit = (EditText)findViewById(R.id.adress_edit); password_edit = (EditText)findViewById(R.id.password_edit); login_edit = (EditText)findViewById(R.id.login_edit); info_edit = (EditText)findViewById(R.id.info_edit); btn_add = (Button)findViewById(R.id.btn_add); btn_add.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v) { try { add_to = new AddG(); add_to.execute(); 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(); } catch(Exception ex) { } } }); } private class AddG extends AsyncTask<Void, Void, String> { String data; String name_data, adress_data, login_data, password_data, info_data; StringBuilder sb; HttpURLConnection conn; protected String doInBackground(Void... params) { try { data = URLEncoder.encode("name", "UTF-8") + "=" + URLEncoder.encode(name_data, "UTF-8") + "&" + URLEncoder.encode("adress", "UTF-8") + "=" + URLEncoder.encode(adress_data, "UTF-8") + "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(password_data, "UTF-8") + "&" + URLEncoder.encode("login", "UTF-8") + "=" + URLEncoder.encode(login_data, "UTF-8") + "&" + URLEncoder.encode("info", "UTF-8") + "=" + URLEncoder.encode(info_data, "UTF-8"); URL url_post = new URL(server_name+"/access/index.php?add"); HttpURLConnection conn = (HttpURLConnection) url_post.openConnection(); conn.setReadTimeout(10000); conn.setConnectTimeout(15000); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write(data); writer.flush(); writer.close(); os.close(); conn.connect(); } catch(Exception e) { } return data; } protected void onPostExecute(String data) { Toast.makeText(getApplicationContext(), "Send to the server... " + data, Toast.LENGTH_SHORT).show(); } } }
application/x-www-form-urlencoded. And then POSTs of two types are at least. And they have a different mime. Who knows what's the default ? Sergey