在Android中发送HTTP POST请求示范

xiaoxiao2022-06-12  36

public void MyFunction{ HttpClient httpclient = new DefaultHttpClient(); //你的URL   HttpPost httppost = new HttpPost("http://www. eoe android.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();   } }
转载请注明原文地址: https://www.6miu.com/read-4933902.html

最新回复(0)