예제 #1
0
        // Execute an API query
        private String _execute_query(OAAPI_Request query)
        {
            // Make the final URL
            String URL = query.encode_arguments();

            // Get the result
            StringBuilder result = new StringBuilder();

            byte[]         buf     = new byte[8192];
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);

            request.UserAgent = "OpenAustralia.org API C# interface (+https://github.com/rubenarakelyan/twfyapi)";
            HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
            Stream          responseStream = response.GetResponseStream();
            int             count          = 0;

            do
            {
                count = responseStream.Read(buf, 0, buf.Length);
                if (count != 0)
                {
                    result.Append(Encoding.ASCII.GetString(buf, 0, count));
                }
            }while (count > 0);
            return(result.ToString());
        }
예제 #2
0
        // Send an API query
        public String query(String func, String[] args)
        {
            // Exit if any arguments are not defined
            if (func == null || func == "" || args == null)
            {
                throw new Exception("ERROR: Function name or arguments not provided.");
            }

            // Construct the query
            OAAPI_Request query = new OAAPI_Request(func, args, this.key);

            // Execute the query
            return(this._execute_query(query));
        }
예제 #3
0
        // Send an API query
        public String query(String func, String[] args)
        {
            // Exit if any arguments are not defined
            if (func == null || func == "" || args == null)
            {
                throw new Exception("ERROR: Function name or arguments not provided.");
            }

            // Construct the query
            OAAPI_Request query = new OAAPI_Request(func, args, this.key);

            // Execute the query
            return this._execute_query(query);
        }
예제 #4
0
        // Execute an API query
        private String _execute_query(OAAPI_Request query)
        {
            // Make the final URL
            String URL = query.encode_arguments();

            // Get the result
            StringBuilder result = new StringBuilder();
            byte[] buf = new byte[8192];
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            int count = 0;
            do
            {
                count = responseStream.Read(buf, 0, buf.Length);
                if (count != 0)
                {
                    result.Append(Encoding.ASCII.GetString(buf, 0, count));
                }
            }
            while (count > 0);
            return result.ToString();
        }