Follow

Code Examples

The HTTP API is commonly used through another programming language or environment, such as PHP or Python.  The benefit is that it can be used by any code that can issue and process HTTP GET or POST transactions.

Java Example

The following is a simple example in Java:

// Display lists public static

String showLists () {     

// cmd = show_lists     

// realm = sample     

// pwd = trelMark9     

// csv = 1 so we’ll get CSV output     

String cmd = “whatcounts.com?cmd=show_lists” +  “&r=sample&pwd=trelMark9&csv=1”;     

// perform an HTTP GET for the data

String results = httpGET (cmd);     

// display our results     

System.out.println (results); }

// Perform an HTTP get for URL public static

String httpGET (String command) {

     String rc = "";

     if (!command.toLowerCase ().startsWith ("http://"))

         command = "http://" + command;

     try

     {

        URL url = new URL (command);

         URLConnection conn = url.openConnection ();

         conn.setDoInput (true);

         conn.setUseCaches (false);

         InputStream is = conn.getInputStream ();

         BufferedReader d = new BufferedReader(new InputStreamReader(is));

         String line = "";

         while ((line = d.readLine ()) != null)

             rc += line + "\n";

         d.close ();

         is.close ();

     }

     catch (Exception e)

    {

    }

     return rc; }  

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk