title: How to consume Monit Web Service API java
body: <p>I'm trying to connect with monit web service api (Restful Services), using the following code:</p>
  
  <pre><code>HttpClient client = new DefaultHttpClient();
  HttpPost httpPost = new HttpPost("http://localhost:2812/z_security_check");
  
  NameValuePair[] credentials = {
                  new BasicNameValuePair("z_username", "admin"),
                  new BasicNameValuePair("z_password", "monit"),
                  new BasicNameValuePair("z_csrf_protection", "off")
          };
  
   List&lt;NameValuePair&gt; body = Arrays.asList(credentials);
  
   httpPost.setEntity(new UrlEncodedFormEntity(body));
   HttpResponse response = client.execute(httpPost);
  
   System.out.println("Post parameters : " + httpPost.getEntity().getContent());
          System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
  
   BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  
   StringBuffer result = new StringBuffer();
   String line = "";
   while ((line = rd.readLine()) != null) {
              result.append(line);
   }
  
   System.out.println(result.toString());
  </code></pre>
  
  <p>But always I have the same answer:</p>
  
  <pre><code>Post parameters : java.io.ByteArrayInputStream@79d0569b
  Response Code : 401
  &lt;html&gt;&lt;head&gt;&lt;title&gt;401 Unauthorized&lt;/title&gt;&lt;/head&gt;&lt;body bgcolor=#FFFFFF&gt;&lt;h2&gt;Unauthorized&lt;/h2&gt;You are not authorized to access monit. Either you supplied the wrong credentials (e.g. bad password), or your browser doesn't understand how to supply the credentials required&lt;hr&gt;&lt;a href='http://mmonit.com/monit/'&gt;&lt;font size=-1&gt;monit 5.14&lt;/font&gt;&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;
  
  Process finished with exit code 0
  </code></pre>
  
  <p>but when I enter via browser (http: // localhost: 2812 /) asked me the credentials and displays the information correctly</p>