Ejemplo n.º 1
0
        private string POST(string callName, string callPrefix, AlchemyAPI_BaseParams parameters)
        {
            // callMethod, callPrefix, ... params
            var address = new Uri(_requestUri + callPrefix + "/" + callName);

            var wreq = WebRequest.Create(address) as HttpWebRequest;

            wreq.Proxy       = null;
            wreq.Method      = "POST";
            wreq.ContentType = "application/x-www-form-urlencoded";

            var d = new StringBuilder();

            d.Append("apikey=").Append(_apiKey).Append(parameters.getParameterString());

            parameters.resetBaseParams();

            byte[] bd = Encoding.UTF8.GetBytes(d.ToString());

            wreq.ContentLength = bd.Length;
            using (Stream ps = wreq.GetRequestStream())
            {
                ps.Write(bd, 0, bd.Length);
            }

            return(DoRequest(wreq, parameters.getOutputMode()));
        }
Ejemplo n.º 2
0
        private string GET(string callName, string callPrefix, AlchemyAPI_BaseParams parameters)
        {
            // callMethod, callPrefix, ... params
            var uri = new StringBuilder();

            uri.Append(_requestUri).Append(callPrefix).Append("/").Append(callName);
            uri.Append("?apikey=").Append(_apiKey).Append(parameters.getParameterString());

            parameters.resetBaseParams();

            var address = new Uri(uri.ToString());
            var wreq    = WebRequest.Create(address) as HttpWebRequest;

            wreq.Proxy = null;

            byte[] postData = parameters.GetPostData();

            if (postData == null)
            {
                wreq.Method = "GET";
            }
            else
            {
                wreq.Method = "POST";
                using (Stream ps = wreq.GetRequestStream())
                {
                    ps.Write(postData, 0, postData.Length);
                }
            }

            return(DoRequest(wreq, parameters.getOutputMode()));
        }
Ejemplo n.º 3
0
        private string POST(string callName, string callPrefix, AlchemyAPI_BaseParams parameters)
        {
            // callMethod, callPrefix, ... params
            var address = new Uri(_requestUri + callPrefix + "/" + callName);

            var wreq = WebRequest.Create(address) as HttpWebRequest;
            wreq.Proxy = null;
            wreq.Method = "POST";
            wreq.ContentType = "application/x-www-form-urlencoded";

            var d = new StringBuilder();
            d.Append("apikey=").Append(_apiKey).Append(parameters.getParameterString());

            parameters.resetBaseParams();

            byte[] bd = Encoding.UTF8.GetBytes(d.ToString());

            wreq.ContentLength = bd.Length;
            using (Stream ps = wreq.GetRequestStream())
            {
                ps.Write(bd, 0, bd.Length);
            }

            return DoRequest(wreq, parameters.getOutputMode());
        }
Ejemplo n.º 4
0
        private string GET(string callName, string callPrefix, AlchemyAPI_BaseParams parameters)
        {
            // callMethod, callPrefix, ... params
            var uri = new StringBuilder();
            uri.Append(_requestUri).Append(callPrefix).Append("/").Append(callName);
            uri.Append("?apikey=").Append(_apiKey).Append(parameters.getParameterString());

            parameters.resetBaseParams();

            var address = new Uri(uri.ToString());
            var wreq = WebRequest.Create(address) as HttpWebRequest;
            wreq.Proxy = null;

            byte[] postData = parameters.GetPostData();

            if (postData == null)
            {
                wreq.Method = "GET";
            }
            else
            {
                wreq.Method = "POST";
                using (Stream ps = wreq.GetRequestStream())
                {
                    ps.Write(postData, 0, postData.Length);
                }
            }

            return DoRequest(wreq, parameters.getOutputMode());
        }
Ejemplo n.º 5
0
        private string DoRequest(HttpWebRequest wreq, AlchemyAPI_BaseParams.OutputMode outputMode)
        {
            using (var wres = wreq.GetResponse() as HttpWebResponse)
            {
                var r = new StreamReader(wres.GetResponseStream());

                var json = r.ReadToEnd();

                return json;
            }
        }