public class HttpUtil {
public static String send(Map<String,String> map,String path){
String rs = null;
HttpPost hp = new HttpPost(path);
DefaultHttpClient hc = new DefaultHttpClient();
List<NameValuePair> list = new ArrayList<NameValuePair>();
try {
Set keys = map.entrySet();
Iterator it = keys.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String key = (String) entry.getKey();
String value = (String) entry.getValue();
BasicNameValuePair nm = new BasicNameValuePair(key, value);
list.add(nm);
}
HttpEntity entity = new UrlEncodedFormEntity(list,HTTP.UTF_8);
hp.setEntity(entity);
HttpResponse response = hc.execute(hp);
if (response.getStatusLine().getStatusCode() == 200) {
entity = response.getEntity();
rs = EntityUtils.toString(entity);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return rs;
}
}