新浪短连接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; }
} }
转载请标明出处!谢谢!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现