• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to pass parameter to server

I am a new member in Android app. I try to pass some parameter to server by this code. But it is like wrong. please help me!
URL url;
String response = "";
HttpURLConnection conn = null;
try {
url = new URL("http://2.mobileprojecttest.appspot.com/completedemo_serverlet");
try{
conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);

//get an output stream from the connection
OutputStreamWriter out = new OutputStreamWriter(
conn.getOutputStream());
out.write("type="+URLEncoder.encode("register","UTF-8"));
}catch(IOException e){
e.printStackTrace();
}
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
try{
while((line = rd.readLine())!=null){
response += line;
}
tx.setText(response);
}catch(IOException e){
e.printStackTrace();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText( this, "Response:"+response, Toast.LENGTH_SHORT).show();
Log.i("Response",""+response);
tv.setText(response);
Thank you!
 
Back
Top Bottom