Android Open Source - BlockchainWidget W S Client






From Project

Back to project page BlockchainWidget.

License

The source code is released under:

The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and nei...

If you think the Android project BlockchainWidget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rbonestell.bcwidget.utils;
/*from   www .  j ava  2s .  co m*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

/***
 * HTTP client
 */
public class WSClient
{
  
  public enum RequestType { GET, POST, UPDATE, DELETE };
  
  /***
   * Send web request
   * @param targetURL Target web service URL including query parameters
   * @return Raw JSON response
   */
  public static String sendRequest(String targetURL, RequestType reqType)
  {
        String line;
        String response = "";
        try
        {
          URL url = new URL(targetURL);
          HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
      conn.setRequestMethod(reqType.toString());
      conn.setReadTimeout(10000);
      conn.setConnectTimeout(15000);
      conn.setDoInput(true);
      
      if (conn.getResponseCode() == HttpURLConnection.HTTP_OK)
      {
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        
        while ((line = rd.readLine()) != null)
          response += line;
        
        rd.close();  
      }
      else
      {
        response = "Error: " + conn.getResponseCode() + " " + conn.getResponseMessage();
      }
      
      conn.disconnect();
    }
        catch (Exception e)
        {
      response = "Error: " + e.getMessage();
    }
        return response;
  }
}




Java Source Code List

com.rbonestell.bcwidget.BlockchainWidget.java
com.rbonestell.bcwidget.SelectFrequencyActivity.java
com.rbonestell.bcwidget.utils.BlockchainRequest.java
com.rbonestell.bcwidget.utils.BlockchainResponse.java
com.rbonestell.bcwidget.utils.WSClient.java