package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class SimplePOST extends Activity {
private TextView show;
private EditText txt;
private Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
(savedInstanceState);
setContentView();
show = (TextView)findViewById();
txt = (EditText)findViewById();
btn = (Button)findViewById();
(new OnClickListener() {
@Override
public void onClick(View v) {
dopost(().toString());
}
});
}
private void dopost(String val){
//Encapsulate data
Map<String, String> parmas = new HashMap<String, String>();
("name", val);
DefaultHttpClient client = new DefaultHttpClient();//http client
HttpPost httpPost = new HttpPost("/test/");
ArrayList<BasicNameValuePair> pairs = new ArrayList<BasicNameValuePair>();
if(parmas != null){
Set<String> keys = ();
for(Iterator<String> i = (); ();) {
String key = (String)();
(new BasicNameValuePair(key, (key)));
}
}
try {
UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(pairs, "utf-8");
/*
* Put POST data into HTTP request
*/
(p_entity);
/*
* Make an actual HTTP POST request
*/
HttpResponse response = (httpPost);
HttpEntity entity = ();
InputStream content = ();
String returnConnection = convertStreamToString(content);
(returnConnection);
} catch (IllegalStateException e) {
();
} catch (IOException e) {
();
}
}
private String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = ()) != null) {
(line);
}
} catch (IOException e) {
();
} finally {
try {
();
} catch (IOException e) {
();
}
}
return ();
}
}