Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.entity.StringEntity;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.util.EntityUtils;
- public class GetData {
- public static String parse(String jsonLine) {
- System.out.println(jsonLine);
- String s[] = jsonLine.split("\"result\":\"");
- String s2[] = s[1].split("\",\"");
- System.err.println(s2[0]);
- return s2[0];
- }
- public static void main(String[] args) throws UnsupportedEncodingException {
- DefaultHttpClient client = new DefaultHttpClient();
- HttpPost post = new HttpPost("http://localhost/index.php?r=admin/remotecontrol");
- post.setHeader("Content-type", "application/json");
- post.setEntity(new StringEntity(
- "{\"method\": \"get_session_key\", \"params\": [\"admin\", \"password\" ], \"id\": 1}"));
- try {
- HttpResponse response = client.execute(post);
- if (response.getStatusLine().getStatusCode() == 200) {
- System.out.println(response.getStatusLine());
- HttpEntity entity = response.getEntity();
- String sessionKey = parse(EntityUtils.toString(entity));
- post.setEntity(new StringEntity("{\"method\": \"list_groups\", \"params\": [ \"" + sessionKey
- + "\", \"289946\" ], \"id\": 60}"));
- response = client.execute(post);
- if (response.getStatusLine().getStatusCode() == 200) {
- entity = response.getEntity();
- System.out.println(EntityUtils.toString(entity));
- }
- post.setEntity(new StringEntity("{\"method\": \"export_responses\", \"params\": "
- + "[ \"" + sessionKey + "\" , \"289946\" , \"json\" , \"en\" , \"\" , \"\" , \"long\", \"61\" , \"61\"], \"id\": 60}"));
- response = client.execute(post);
- if (response.getStatusLine().getStatusCode() == 200) {
- entity = response.getEntity();
- System.out.println(EntityUtils.toString(entity));
- }
- }
- } catch (
- IOException e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment