public GoogleCustomSearchResponse Search(string query)
        {
            string googleCustomSearchApiKeyUrl = ConfigurationManager.AppSettings[Constants.GOOGLE_CUSTOM_SEARCH_API_KEY_URL];
            string googleSearchEngine          = ConfigurationManager.AppSettings[Constants.GOOGLE_SEARCH_ENGINE];
            string googleCustomSearchApiKey    = ConfigurationManager.AppSettings[Constants.GOOGLE_CUSTOM_SEARCH_API_KEY];

            using (var httpWebResponse = (HttpWebResponse)WebRequest.Create(string.Format(googleCustomSearchApiKeyUrl, googleCustomSearchApiKey, googleSearchEngine, query)).GetResponse())
            {
                return(HttpResponseHandler.GetDeserializedObjectFromResponse <GoogleCustomSearchResponse>(httpWebResponse));
            }
        }
示例#2
0
        public BingWebSearchResponse Search(string query)
        {
            string bingWebSearchApiKeyUrl        = ConfigurationManager.AppSettings[Constants.BING_WEB_SEARCH_API_URL];
            string bingWebSearchApiKey1          = ConfigurationManager.AppSettings[Constants.BING_WEB_SEARCH_API_KEY_1];
            string bingWebSearchApiKeyHeaderName = ConfigurationManager.AppSettings[Constants.BING_WEB_SEARCH_API_KEY_HEADER_NAME];

            var webRequest = WebRequest.Create(string.Format(bingWebSearchApiKeyUrl, query));

            webRequest.Headers[bingWebSearchApiKeyHeaderName] = bingWebSearchApiKey1;

            using (var httpWebResponse = (HttpWebResponse)webRequest.GetResponse())
            {
                return(HttpResponseHandler.GetDeserializedObjectFromResponse <BingWebSearchResponse>(httpWebResponse));
            }
        }