Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Map<String,Object> post(String url, Map<String,String> args) throws UnsupportedEncodingException{
- Map<String,Object> map = new HashMap<String,Object>();
- HttpParams params = new BasicHttpParams();
- for(String kv : args.keySet()){
- params.setParameter(kv, args.get(kv));
- Log.i("_params", kv + " -> " + args.get(kv));
- }
- Log.i("_data", params.toString());
- BufferedReader in = null;
- try {
- HttpClient client = new DefaultHttpClient();
- HttpPost request = new HttpPost(url);
- request.setParams(params);
- HttpResponse response = client.execute(request);
- in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
- StringBuffer sb = new StringBuffer("");
- String line = "";
- String NL = System.getProperty("line.separator");
- while ((line = in.readLine()) != null) {
- sb.append(line + NL);
- }
- in.close();
- String page = sb.toString();
- Log.i("_http_response", page);
- map.put("status_code", Integer.toString(response.getStatusLine().getStatusCode()));
- map.put("body", page);
- } catch (IllegalStateException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return map;
- }
Add Comment
Please, Sign In to add comment