zoukankan      html  css  js  c++  java
  • C#生成新浪微博短网址 示例源码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
       
    using DotNetSample.Models;
    using System.Web.Script.Serialization;
       
    namespace DotNetSample.Utils
    {
        public class ShortUrlHelper
        {
            /// <summary>
            /// 获取新浪短域名
            /// </summary>
            /// <param name="url">原始地址</param>
            /// <returns></returns>
            public static ShortUrl SinaShortUrl(string url)
            {
                string builder = HtmlEncode.GetUrlHtml("http://api.t.sina.com.cn/short_url/shorten.json?source=1681459862&url_long="   System.Web.HttpContext.Current.Server.UrlEncode(url)).Replace("[""").Replace("]""");
                   
                return new JavaScriptSerializer().Deserialize<ShortUrl>(builder);
            }
        }
     
     
        [Serializable]
        public class ShortUrl
        {
            /// <summary>
            /// 短域名
            /// </summary>
            public virtual string url_short { getset; }
       
            /// <summary>
            /// 长域名
            /// </summary>
            public virtual string url_long { getset; }
       
            /// <summary>
            /// 类型
            /// </summary>
            public virtual int type { getset; }
        }
     
     
    }
  • 相关阅读:
    二分查找算法
    http协议。会话控制cookie、session
    154. Find Minimum in Rotated Sorted Array II
    8. String to Integer (atoi)
    528. Random Pick with Weight
    415. Add Strings
    158. Read N Characters Given Read4 II
    157. Read N Characters Given Read4
    19. Remove Nth Node From End of List
    29. Divide Two Integers
  • 原文地址:https://www.cnblogs.com/hclw/p/5995908.html
Copyright © 2011-2022 走看看