当前位置: 首页>>代码示例>>C#>>正文


C# UrlBuilder.Add方法代码示例

本文整理汇总了C#中UrlBuilder.Add方法的典型用法代码示例。如果您正苦于以下问题:C# UrlBuilder.Add方法的具体用法?C# UrlBuilder.Add怎么用?C# UrlBuilder.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UrlBuilder的用法示例。


在下文中一共展示了UrlBuilder.Add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TranslateV2

 public string TranslateV2(string word, string target)
 {
     const string api = "https://www.googleapis.com/language/translate/v2/languages";
     UrlBuilder urlBuilder = new UrlBuilder(api);
     urlBuilder.Add("key","11111");
     urlBuilder.Add("target","en");
     urlBuilder.Add("q", word);
     string resJson = webHelper.Get(urlBuilder);
     NameValueCollection nameValue = JsonConvert.ToNameValue(resJson);
     return nameValue["responseData"];
 }
开发者ID:marinehero,项目名称:ThinkAway.net,代码行数:11,代码来源:GoogleTranslate.cs

示例2: TranslateV1

 public string TranslateV1(string sourceWord, string fromLanguage, string toLanguage)
 {
     /* 
      调用: http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=zh-CN|en&q=中国
      返回的json格式如下:
      {"responseData": {"translatedText":"Chinese people are good people"}, "responseDetails": null, "responseStatus": 200}*/
     const string api = "http://ajax.googleapis.com/ajax/services/language/translate";
     UrlBuilder urlBuilder = new UrlBuilder(api);
     urlBuilder.Add("v", "1.0");
     urlBuilder.Add("langpair", string.Format("{0}|{1}", fromLanguage, toLanguage));
     urlBuilder.Add("q",sourceWord);
     
     string resJson = webHelper.Get(urlBuilder);
     NameValueCollection nameValue = JsonConvert.ToNameValue(resJson);
     return nameValue["responseData"];
 }
开发者ID:marinehero,项目名称:ThinkAway.net,代码行数:16,代码来源:GoogleTranslate.cs

示例3: GenerateUrl

 public static string GenerateUrl(string controller, string action, 
     object[] parameters, List<KeyValuePair<string, string>> urlParam)
 {
     string appPath = HttpContextHandler.Instance.ApplicationPath.ToLower();
     var url = new StringBuilder();
     url.Append(appPath);
     if (!string.IsNullOrEmpty(appPath) && !appPath.EndsWith("/"))
     {
         url.Append("/");
     }
     url.Append(controller.ToLower()).Append("/");
     if (!string.IsNullOrEmpty(action))
     {
         url.Append(action.ToLower()).Append("/");
     }
     if (parameters != null)
     {
         foreach (var o in parameters)
         {
             if (o != null)
             {
                 AppendParameter(url, o);
             }
         }
     }
     url.Length--;
     if (WebSettings.MvcPostfix != "")
     {
         url.Append(WebSettings.MvcPostfix);
     }
     var s =  url.ToString();
     if(urlParam != null)
     {
         var ub = new UrlBuilder(s, Encoding.UTF8);
         foreach (var kv in urlParam)
         {
             ub.Add(kv.Key, kv.Value);
         }
         return ub.ToString();
     }
     return s;
 }
开发者ID:991899783,项目名称:DbEntry,代码行数:42,代码来源:UrlToInfo.cs

示例4: GetWeather

        /// <summary>
        /// get weather with city
        /// </summary>
        /// <param name="city"></param>
        /// <returns></returns>
        public Weather GetWeather(string city)
        {
            const string baseUrl = @"https://www.google.com";
            UrlBuilder urlBuilder = new UrlBuilder(string.Format(@"{0}/ig/api", baseUrl));
            urlBuilder.Add("hl", "zh-cn");
            urlBuilder.Add("weather", city);

            string weatherXml = webHelper.Get(urlBuilder);
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(weatherXml);
            XmlNodeList nodeCity = xmlDocument.SelectNodes("xml_api_reply/weather/forecast_information");
            Weather.CityInfomaition cityInfo = new Weather.CityInfomaition(
                nodeCity.Item(0).SelectSingleNode("city").Attributes["data"].InnerText,
                nodeCity.Item(0).SelectSingleNode("postal_code").Attributes["data"].InnerText,
                nodeCity.Item(0).SelectSingleNode("latitude_e6").Attributes["data"].InnerText,
                nodeCity.Item(0).SelectSingleNode("longitude_e6").Attributes["data"].InnerText,
                nodeCity.Item(0).SelectSingleNode("unit_system").Attributes["data"].InnerText,
                Convert.ToDateTime(nodeCity.Item(0).SelectSingleNode("forecast_date").Attributes["data"].InnerText),
                Convert.ToDateTime(nodeCity.Item(0).SelectSingleNode("current_date_time").Attributes["data"].InnerText));
            XmlNodeList nodeToday = xmlDocument.SelectNodes("xml_api_reply/weather/current_conditions");
            Weather.TodayWeather today = new Weather.TodayWeather(
                Convert.ToInt16(nodeToday.Item(0).SelectSingleNode("temp_c").Attributes["data"].InnerText),
                Convert.ToInt16(nodeToday.Item(0).SelectSingleNode("temp_f").Attributes["data"].InnerText),
                nodeToday.Item(0).SelectSingleNode("condition").Attributes["data"].InnerText,
                nodeToday.Item(0).SelectSingleNode("humidity").Attributes["data"].InnerText,
                nodeToday.Item(0).SelectSingleNode("wind_condition").Attributes["data"].InnerText,
                new ImageHelper(baseUrl + nodeToday.Item(0).SelectSingleNode("icon").Attributes["data"].InnerText).Image);

            XmlNodeList nodeList = xmlDocument.SelectNodes("xml_api_reply/weather/forecast_conditions");
            Weather.DayWeather[] dayWeathers = new Weather.DayWeather[nodeList.Count];
            for (int i = 0; i < nodeList.Count; i++)
            {
                string dayOfWeek = nodeList.Item(i).SelectSingleNode("day_of_week").Attributes["data"].InnerText;
                string height = nodeList.Item(i).SelectSingleNode("high").Attributes["data"].InnerText;
                string width = nodeList.Item(i).SelectSingleNode("low").Attributes["data"].InnerText;
                string condition = nodeList.Item(i).SelectSingleNode("condition").Attributes["data"].InnerText;
                string icon = nodeList.Item(i).SelectSingleNode("icon").Attributes["data"].InnerText;
                Weather.DayWeather dayWeather = new Weather.DayWeather(
                    dayOfWeek,
                    Convert.ToInt16(height),
                    Convert.ToInt16(width),
                    condition,
                    new ImageHelper(string.Concat(baseUrl, icon)).Image
                    );
                dayWeathers[i] = dayWeather;
            }
            Weather weather = new Weather(cityInfo, today, dayWeathers);
            return weather;
        }
开发者ID:marinehero,项目名称:ThinkAway.net,代码行数:54,代码来源:GoogleWeather.cs

示例5: GoogleWeather

 public static Weather GoogleWeather(string city)
 {
     const string baseUrl = @"https://www.google.com";
     WebHelper connectionBase = new WebHelper();
     UrlBuilder parameters = new UrlBuilder(string.Format(@"{0}/ig/api", baseUrl));
     parameters.Add("hl","zh-cn");
     parameters.Add("weather",city);
     XmlDocument xmlDocument = new XmlDocument();
    xmlDocument.LoadXml(connectionBase.Get(parameters.ToString()));
     XmlNodeList nodeCity = xmlDocument.SelectNodes("xml_api_reply/weather/forecast_information");
     Weather.CityInfomaition cityInfo = new Weather.CityInfomaition(
         nodeCity.Item(0).SelectSingleNode("city").Attributes["data"].InnerText,
         nodeCity.Item(0).SelectSingleNode("postal_code").Attributes["data"].InnerText,
         nodeCity.Item(0).SelectSingleNode("latitude_e6").Attributes["data"].InnerText,
         nodeCity.Item(0).SelectSingleNode("longitude_e6").Attributes["data"].InnerText,
         nodeCity.Item(0).SelectSingleNode("unit_system").Attributes["data"].InnerText,
         Convert.ToDateTime(nodeCity.Item(0).SelectSingleNode("forecast_date").Attributes["data"].InnerText),
         Convert.ToDateTime(nodeCity.Item(0).SelectSingleNode("current_date_time").Attributes["data"].InnerText));
     XmlNodeList nodeToday = xmlDocument.SelectNodes("xml_api_reply/weather/current_conditions");
     Weather.TodayWeather today = new Weather.TodayWeather(
         Convert.ToInt16(nodeToday.Item(0).SelectSingleNode("temp_c").Attributes["data"].InnerText),
         Convert.ToInt16(nodeToday.Item(0).SelectSingleNode("temp_f").Attributes["data"].InnerText),
         nodeToday.Item(0).SelectSingleNode("condition").Attributes["data"].InnerText,
         nodeToday.Item(0).SelectSingleNode("humidity").Attributes["data"].InnerText,
         nodeToday.Item(0).SelectSingleNode("wind_condition").Attributes["data"].InnerText,
         ImageHelper.GetImage(baseUrl + nodeToday.Item(0).SelectSingleNode("icon").Attributes["data"].InnerText));
     XmlNodeList nodeList = xmlDocument.SelectNodes("xml_api_reply/weather/forecast_conditions");
     Weather.DayWeather tomorrow = new Weather.DayWeather(
         Convert.ToInt16(nodeList.Item(1).SelectSingleNode("high").Attributes["data"].InnerText),
         Convert.ToInt16(nodeList.Item(1).SelectSingleNode("low").Attributes["data"].InnerText),
         nodeList.Item(1).SelectSingleNode("condition").Attributes["data"].InnerText,
         ImageHelper.GetImage(baseUrl + nodeToday.Item(0).SelectSingleNode("icon").Attributes["data"].InnerText));
     Weather.DayWeather third = new Weather.DayWeather(
         Convert.ToInt16(nodeList.Item(2).SelectSingleNode("high").Attributes["data"].InnerText),
         Convert.ToInt16(nodeList.Item(2).SelectSingleNode("low").Attributes["data"].InnerText),
         nodeList.Item(2).SelectSingleNode("condition").Attributes["data"].InnerText,
         ImageHelper.GetImage(baseUrl + nodeToday.Item(0).SelectSingleNode("icon").Attributes["data"].InnerText));
     Weather.DayWeather fourth = new Weather.DayWeather(
         Convert.ToInt16(nodeList.Item(3).SelectSingleNode("high").Attributes["data"].InnerText),
         Convert.ToInt16(nodeList.Item(3).SelectSingleNode("low").Attributes["data"].InnerText),
         nodeList.Item(3).SelectSingleNode("condition").Attributes["data"].InnerText,
         ImageHelper.GetImage(baseUrl + nodeToday.Item(0).SelectSingleNode("icon").Attributes["data"].InnerText));
     Weather weather = new Weather(cityInfo,today, tomorrow, third, fourth);
     return weather;
 }
开发者ID:marinehero,项目名称:ThinkAway.net,代码行数:45,代码来源:GoogleAPI.cs


注:本文中的UrlBuilder.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。