android http post 传递参数
mButton1.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String uriAPI=”http://211.155.30.105:8000/ttc/?Num=1&Hot=0″;
HttpPost httpRequest=new HttpPost(uriAPI);
List
params.add(new BasicNameValuePair(“str”,”I am Post String”));
try
{
httpRequest.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
HttpResponse httpResponse=new DefaultHttpClient().execute(httpRequest);
if(httpResponse.getStatusLine().getStatusCode()==200)
{
String strResult=EntityUtils.toString(httpResponse.getEntity());
mTextView1.setText(strResult);
}
}
catch(ClientProtocolException e)
{
mTextView1.setText(e.getMessage().toString());
e.printStackTrace();
}
catch(IOException e)
{
mTextView1.setText(e.getMessage().toString());
e.printStackTrace();
}
catch(Exception e)
{
mTextView1.setText(e.getMessage().toString());
e.printStackTrace();
}
}
}
);
