title: i cant send data from android to server by post
body: <p>i cant send data from andorid device to url 
  please help me !
  this is my class
  what is problem of my code ?</p>
  
  <pre><code>package com.example.test;
  
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.net.URL;
  import java.net.URLConnection;
  import java.net.URLEncoder;
  
  import android.os.AsyncTask;
  
  
  
  public class loginserver extends AsyncTask{
  
      private String Link="";
      private String User="";
      private String Pass="";
  
  
  
      public loginserver(String link,String user,String pass){
  
          Link=link;
          User=user;
          Pass=pass;
      }
  
  
  
      @Override
      protected String doInBackground(Object... arg0) {
  
  
          try{
  
              String data=URLEncoder.encode("username","UTF8")+"="+URLEncoder.encode(User,"UTF8");
              data+="&amp;"+URLEncoder.encode("password","UTF8")+"="+URLEncoder.encode(Pass,"UTF8");
  
  
  
              URL mylink=new URL(Link);
              URLConnection connect=mylink.openConnection();
  
              connect.setDoOutput(true);
              OutputStreamWriter wr=new OutputStreamWriter(connect.getOutputStream());
              wr.write(data);
              wr.flush();
  
  
              BufferedReader reader=new BufferedReader(new InputStreamReader(connect.getInputStream()));
              StringBuilder sb=new StringBuilder();
  
              String line=null;
  
              while((line=reader.readLine()) !=null){
  
                  sb.append(line);
  
              }
  
              Main.res = sb.toString();
  
  
  
  
          }catch(Exception e){
  
  
  
          }
  
  
  
          return "";
      }
  
  }
  </code></pre>
  
  <p>and this is my main code
  problem in class code or main code?</p>
  
  <pre><code>package com.example.test;
  
  import java.util.Timer;
  import java.util.TimerTask;
  
  import android.support.v7.app.ActionBarActivity;
  import android.app.Activity;
  import android.app.ProgressDialog;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.webkit.WebStorage.Origin;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Toast;
  
  
  public class Main extends Activity {
  
      public static String res="";
      private EditText usertext,passtext;
      private Button login,register,exit;
  
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          usertext =(EditText) findViewById(R.id.usertext);
          passtext =(EditText) findViewById(R.id.passtext);
  
  
          login =(Button) findViewById(R.id.login);
          exit =(Button) findViewById(R.id.exit);
          register =(Button) findViewById(R.id.register);
  
          login.setOnClickListener(new OnClickListener() {
  
              public void onClick(View arg0) {
  
  login(usertext.getText().toString(),passtext.getText().toString());
  
  
              }
          });
  
  
      }
  
   private void login (String user,String pass ){
  
       new loginserver("my address",user,pass ).execute();
  
       final ProgressDialog pd = new ProgressDialog(Main.this);
       pd.setMessage("please wait");
       pd.show();
  
       final Timer tm = new Timer();
       tm.scheduleAtFixedRate(new TimerTask(){
          public void run() {
          runOnUiThread(new Runnable() {
              public void run() {
  
                  if(res.equals("")){
                      pd.cancel();
                      Toast.makeText(getApplicationContext(), res, Toast.LENGTH_LONG).show(); 
                      tm.cancel();
                  }
  
              }
          });
  
          }
  
       },1, 1000);
   }
  
  }
  </code></pre>
  
  <p>the php code work true - but i cant send data from android device
  is ther any body know my mistakes ?</p>