Hey, ich habe mich gefragt, ob jemand mir einige Beispiel dafür, wie die Verwendung Bit.ly API in ASP.NET 2.0Mit Bit.ly API in ASP.NET 2.0
Antwort
ich wirklich schnell konvertieren getan haben zeigen können aus einer Antwort, die ich in VB gefunden habe.
Ich habe dies nicht getestet (sorry), aber es kann in der Zwischenzeit eine Hilfe sein, und ich sortiere es, um ein bisschen mehr C# Stil freundlich zu sein.
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;
}
Originalcode von hier genommen - http://www.dougv.com/blog/2009/07/02/shortening-urls-with-the-bit-ly-api-via-asp-net/
fand ich die Antwort von tim und es ist ziemlich solide. Ich brauchte eine vb.net-Version, also konvertierte ich sie von C# zurück - ich dachte, das könnte jemandem helfen. Es scheint, dass sich der Link bit.ly geändert hat; nicht sicher, ob die Version mehr benötigt wird; eine kleine Fehlerbehandlung hinzugefügt, falls Sie eine schlechte URL übergeben.
Public Shared Function BitlyIt(ByVal strLongUrl As String) As String
Dim uri As New StringBuilder("http://api.bitly.com/v3/shorten?")
'uri.Append("version=2.0.1") 'doesnt appear to be required
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))
Dim request As HttpWebRequest = TryCast(WebRequest.Create(uri.ToString()), HttpWebRequest)
request.Method = "GET"
request.ContentType = "application/x-www-form-urlencoded"
request.ServicePoint.Expect100Continue = False
request.ContentLength = 0
Dim objResponse As WebResponse = request.GetResponse()
Dim myXML As New StreamReader(objResponse.GetResponseStream())
Dim xr = XmlReader.Create(myXML)
Dim xdoc = XDocument.Load(xr)
If xdoc.Descendants("status_txt").Value = "OK" Then
Return xdoc.Descendants("url").Value
Else
Return "Error " & "ReturnValue: " & xdoc.Descendants("status_txt").Value
End If
End Function
gibt es etwas kürzere Version BitlyIn
public static string BitlyEncrypt2(string user, string apiKey, string pUrl)
{
string uri = "http://api.bit.ly/shorten?version=2.0.1&format=txt" +
"&longUrl=" + HttpUtility.UrlEncode(pUrl) +
"&login=" + HttpUtility.UrlEncode(user) +
"&apiKey=" + HttpUtility.UrlEncode(apiKey);
HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
request.ServicePoint.Expect100Continue = false;
request.ContentLength = 0;
return (new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd());
}
- 1. bit.ly - API Stat Tracking
- 2. Asp.NET Web API 2.0: Schlüsselwörter API-Dokumentation
- 3. Ist es möglich, die Bit.ly-API mit VB.net aufzurufen?
- 4. Datenraster in asp.net 2.0
- 5. GridView in ASP.NET 2.0
- 6. bit.ly cname umleitet - PHP
- 7. Bit.ly API: Alle Links für einen Benutzer auflisten
- 8. API 'advancedBy' in Swift 2.0
- 9. Einstellung Standardschaltfläche in asp.net 2.0
- 10. ASp.net Rollenmanagement in Identity 2.0
- 11. Gridview-Spaltenbreite in ASP.NET 2.0
- 12. Crystal Reports + Asp.net 2.0
- 13. Asp.Net 2.0 Datei-Upload
- 14. Erstellen einer SOAP-Anfrage mit ASP.Net 2.0
- 15. JSON mit ASP.NET 2.0 VB.NET lesen?
- 16. ASP.NET 2.0 - DataGrid mit tbody/thead
- 17. JQGrid DataUrl Verwendung mit ASP.net (MVC 2.0)
- 18. Dynamische JPA 2.0-Abfrage mit Criteria API
- 19. POST mit JAX-RS 2.0-Client-API
- 20. ASP.net Webapi 2.0 behandeln falsche Route
- 21. ASP.NET 2.0 Website erhält ThreadAbortException
- 22. Asp.net Identity 2.0 Update-Benutzer
- 23. wie Silverlight-Anwendung in ASP.net 2.0
- 24. ASP.NET MVC - Ninject 2.0 Aktivierungsfehler
- 25. Erweitern von ASP.NET Identity 2.0
- 26. Ausnahme nach ASP.NET Identity 2.0
- 27. Asp.net 2.0 und C# 3.0?
- 28. Einen API-Aufruf in Swift 2.0 machen
- 29. JSON-API-Beispiele in Swagger 2.0
- 30. OutputCache und Anmelden in ASP.NET MVC 2.0
asp.net 2 oder MVC 2? – stack72
ASP.NET 2, Prost – StevieB