Created
May 12, 2011 03:34
-
-
Save mactive/967885 to your computer and use it in GitHub Desktop.
在Android中发送HTTP POST请求示范
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void MyFunction{ | |
HttpClient httpclient = new DefaultHttpClient(); | |
//你的URL | |
HttpPost httppost = new HttpPost("http://www.eoeandroid.com/post_datas.php"); | |
try { | |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); | |
//Your DATA | |
nameValuePairs.add(new BasicNameValuePair("id", "12345")); | |
nameValuePairs.add(new BasicNameValuePair("stringdata", "eoeAndroid.com is Cool!")); | |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); | |
HttpResponse response; | |
response=httpclient.execute(httppost); | |
} catch (ClientProtocolException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment