2013年6月24日 星期一

如何從android client post中文到server去?

Just give me the code!!
==============================
....
....
....
 HttpPost httppost = new HttpPost("http://"+SERVER_ADDRESS+destPath);
       // Add your param
   java.util.Iterator<String> keys= keyAndValue.keySet().iterator();
       List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
   while(keys.hasNext()){
    String key=keys.next();
    String value=keyAndValue.get(key);
       nameValuePairs.add(new BasicNameValuePair(key, value));
   }
       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8));
       
       // Execute HTTP Post Request
       HttpResponse response = httpclient.execute(httppost);
     
       BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
       String str=reader.readLine();
   ...
  ....
  ...
==============================================================

沒有留言:

張貼留言