• 新浪短连接API免登陆免认证实例


    string source = "source=2849184197"; // APP Key,这个可以根据自己需要去网上搜索
    string url_long = $"url_long=http://baidu.com?id={id}"; //自己的访问地址
    string data = Func.HttpNet.GetData($"?{ source}&{url_long}", $"http://api.weibo.com/2/short_url/shorten.json");//get请求API返回短连接数据
    var jsonObject = LitJson.JsonMapper.ToObject<Func.WeiBoLnk>(data);//返回的string格式转换成对象

    实体类对象

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace Game.Web.Func
    {
        public class WeiBoLnk
        {
            public List<Urls> urls { get; set; }
    
        }
    
        public class Urls
        {
            public bool result { get; set; }
            public string url_short { get; set; }
            public string url_long { get; set; }
            public string object_type { get; set; }
            public int type { get; set; }
            public string object_id { get; set; }
        }
    }

    API请求的代码

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Web;
    
    namespace Game.Web.Func
    {
        public class HttpNet
        {
            /// <summary>
            /// 以GET 形式获取数据
            /// </summary>
            /// <param name="RequestPara"></param>
            /// <param name="Url"></param>
            /// <returns></returns>
    
            public static string GetData(string RequestPara, string Url)
            {
                RequestPara = RequestPara.IndexOf('?') > -1 ? (RequestPara) : ("?" + RequestPara);
    
                WebRequest hr = HttpWebRequest.Create(Url + RequestPara);
    
                byte[] buf = System.Text.Encoding.GetEncoding("utf-8").GetBytes(RequestPara);
                hr.Method = "GET";
    
                System.Net.WebResponse response = hr.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
                string ReturnVal = reader.ReadToEnd();
                reader.Close();
                response.Close();
    
                return ReturnVal;
            }
      } }
    转载请标明出处!谢谢!
  • 相关阅读:
    Codeforces 1163E 高斯消元 + dfs
    Codeforces 1159E 拓扑排序
    Codeforces 631E 斜率优化
    Codeforces 1167F 计算贡献
    Codeforces 1167E 尺取法
    Gym 102007I 二分 网络流
    Codeforces 319C DP 斜率优化
    Codeforces 1163D DP + KMP
    Comet OJ
    Vue 的响应式原理中 Object.defineProperty 有什么缺陷?为什么在 Vue3.0 采用了 Proxy,抛弃了 Object.defineProperty?
  • 原文地址:https://www.cnblogs.com/nnnnnn/p/10779204.html
Copyright © 2020-2023  润新知