示例#1
0
        private string RequestCore(string address)
        {
            _output = GeoCoderOutput.Xml;

            var queryString = new QueryStringParameterCollection();

            queryString.Add("address", address);
            queryString.Add("sensor", "false");

            var url = string.Format("{0}/{1}{2}", ApiUrl, _output.ToString().ToLowerInvariant(), queryString);

            var req = (HttpWebRequest)WebRequest.Create(url);
            var res = (HttpWebResponse)req.GetResponse();

            string responseString;

            if (res == null)
            {
                throw new WebException("Can't get response from service.");
            }

            var responseContent = res.GetResponseStream();

            if (responseContent == null)
            {
                throw new WebException("Can't get response from service.");
            }

            using (var reader = new StreamReader(responseContent))
            {
                responseString = reader.ReadToEnd();
            }

            return(responseString);
        }
示例#2
0
        private string RequestCore(string address)
        {
            _output = GeoCoderOutput.Xml;

            var queryString = new QueryStringParameterCollection();

            queryString.Add("address", address);
            queryString.Add("sensor", "false");

            var url = string.Format("{0}/{1}{2}", ApiUrl, _output.ToString().ToLowerInvariant(), queryString);

            var req = (HttpWebRequest) WebRequest.Create(url);
            var res = (HttpWebResponse) req.GetResponse();

            string responseString;

            if (res == null) throw new WebException("Can't get response from service.");

            var responseContent = res.GetResponseStream();

            if (responseContent == null) throw new WebException("Can't get response from service.");

            using (var reader = new StreamReader(responseContent))
            {
                responseString = reader.ReadToEnd();
            }

            return responseString;
        }