- Posts: 8
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
import java.io.IOException; import java.io.UnsupportedEncodingException; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; public class Main { public static String parse(String jsonLine) { JsonElement jelement = new JsonParser().parse(jsonLine); JsonObject jobject = jelement.getAsJsonObject(); String result = jobject.get("result").getAsString(); return result; } public static void main(String[] args) throws UnsupportedEncodingException { HttpClient client = HttpClientBuilder.create().build(); HttpPost post = new HttpPost("https://lime.ciro.it/admin/remotecontrol"); post.setHeader("Content-type", "application/json"); post.setEntity(new StringEntity("{\"method\": \"get_session_key\", \"params\": [\"admin\", \"password\" ], \"id\": 531612}")); try { HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); String sessionKey = parse(EntityUtils.toString(entity)); post.setEntity(new StringEntity("{\"method\": \"get_survey_properties\", \"params\": [ \"" + sessionKey + "\", 531612 ]}")); response = client.execute(post); if (response.getStatusLine().getStatusCode() == 200) { entity = response.getEntity(); System.out.print(entity); //STRANGE System.out.println(EntityUtils.toString(entity)); }else{ System.out.print(response); } } } catch (IOException e) { e.printStackTrace(); } } }