gpt4 book ai didi

asp.net - 在 ASP.NET 2.0 中使用 Bit.ly API

转载 作者:行者123 更新时间:2023-12-04 19:20:28 26 4
gpt4 key购买 nike

嘿,我想知道是否有人可以指出一些有关如何在 ASP.NET 2.0 中使用 Bit.ly API 的示例

最佳答案

我已经从我在 VB 中找到的答案进行了非常快速的转换。

我还没有测试过这个(抱歉),但在此期间它可能会有所帮助,我将对其进行整理以使其对 C# 风格更加友好。

public static string BitlyIt(string user, string apiKey, string strLongUrl)
{
StringBuilder uri = new StringBuilder("http://api.bit.ly/shorten?");

uri.Append("version=2.0.1");

uri.Append("&format=xml");
uri.Append("&longUrl=");
uri.Append(HttpUtility.UrlEncode(strLongUrl));
uri.Append("&login=");
uri.Append(HttpUtility.UrlEncode(user));
uri.Append("&apiKey=");
uri.Append(HttpUtility.UrlEncode(apiKey));

HttpWebRequest request = WebRequest.Create(uri.ToString()) as HttpWebRequest;
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.ServicePoint.Expect100Continue = false;
request.ContentLength = 0;
WebResponse objResponse = request.GetResponse();
XmlDocument objXML = new XmlDocument();
objXML.Load(objResponse.GetResponseStream());

XmlNode nShortUrl = objXML.SelectSingleNode("//shortUrl");

return nShortUrl.InnerText;
}

从这里获取的原始代码 -
http://www.dougv.com/blog/2009/07/02/shortening-urls-with-the-bit-ly-api-via-asp-net/

关于asp.net - 在 ASP.NET 2.0 中使用 Bit.ly API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3979271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com