Guest User

Untitled

a guest
Mar 22nd, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.UnsupportedEncodingException;
  3.  
  4. import org.apache.http.HttpEntity;
  5. import org.apache.http.HttpResponse;
  6. import org.apache.http.client.methods.HttpPost;
  7. import org.apache.http.entity.StringEntity;
  8. import org.apache.http.impl.client.DefaultHttpClient;
  9. import org.apache.http.util.EntityUtils;
  10.  
  11. public class GetData {
  12.  
  13.     public static String parse(String jsonLine) {
  14.         System.out.println(jsonLine);
  15.         String s[] = jsonLine.split("\"result\":\"");
  16.         String s2[] = s[1].split("\",\"");
  17.         System.err.println(s2[0]);
  18.         return s2[0];
  19.     }
  20.  
  21.     public static void main(String[] args) throws UnsupportedEncodingException {
  22.         DefaultHttpClient client = new DefaultHttpClient();
  23.  
  24.         HttpPost post = new HttpPost("http://localhost/index.php?r=admin/remotecontrol");
  25.         post.setHeader("Content-type", "application/json");
  26.         post.setEntity(new StringEntity(
  27.                 "{\"method\": \"get_session_key\", \"params\": [\"admin\", \"password\" ], \"id\": 1}"));
  28.         try {
  29.             HttpResponse response = client.execute(post);
  30.             if (response.getStatusLine().getStatusCode() == 200) {
  31.                 System.out.println(response.getStatusLine());
  32.  
  33.                 HttpEntity entity = response.getEntity();
  34.                 String sessionKey = parse(EntityUtils.toString(entity));
  35.  
  36.                 post.setEntity(new StringEntity("{\"method\": \"list_groups\", \"params\": [ \"" + sessionKey
  37.                         + "\", \"289946\" ], \"id\": 60}"));
  38.                 response = client.execute(post);
  39.                 if (response.getStatusLine().getStatusCode() == 200) {
  40.                     entity = response.getEntity();
  41.                     System.out.println(EntityUtils.toString(entity));
  42.                 }
  43.  
  44.                 post.setEntity(new StringEntity("{\"method\": \"export_responses\", \"params\": "
  45.                         + "[ \"" + sessionKey + "\" , \"289946\" , \"json\" , \"en\" , \"\" , \"\" , \"long\", \"61\" , \"61\"], \"id\": 60}"));
  46.                 response = client.execute(post);
  47.                 if (response.getStatusLine().getStatusCode() == 200) {
  48.                     entity = response.getEntity();
  49.                     System.out.println(EntityUtils.toString(entity));
  50.                 }
  51.  
  52.             }
  53.  
  54.         } catch (
  55.  
  56.         IOException e) {
  57.             e.printStackTrace();
  58.         }
  59.     }
  60. }
Add Comment
Please, Sign In to add comment