Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestHttpClient {
- public static void main(String[] args) throws UnsupportedEncodingException {
- DefaultHttpClient client = new DefaultHttpClient();
- HttpHost targetHost = new HttpHost("name_server",80,"http");
- UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("Myusername", "MyPsw");
- ((DefaultHttpClient)client).getCredentialsProvider().setCredentials(new AuthScope(targetHost), credentials);
- StringEntity params =new StringEntity("username=,password=");
- HttpPost post = new HttpPost("/index.php/admin/remotecontrol/get_session_key");
- post.setHeader("Content-type", "application/json");
- post.setEntity(params);
- try {
- List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
- nameValuePairs.add(new BasicNameValuePair("username", "Myusername"));
- nameValuePairs.add(new BasicNameValuePair("password", "MyPsw"));
- post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
- HttpResponse response = client.execute(targetHost,post);
- System.out.println(response);
- if(response.getStatusLine().getStatusCode() == 200){
- HttpEntity entity = response.getEntity();
- BufferedReader rd = new BufferedReader(new InputStreamReader(entity.getContent()));
- String line = "";
- while ((line = rd.readLine()) != null) {
- line += line;
- }
- String esito = line;
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement