在.Net应用程序中使用tinyurl.com...可能吗?
我找到了以下代码来创建一个tinyurl.com url:
http://tinyurl.com/api-create.php?url=http://myurl.com
这将自动创建一个tinyurl url。 有没有办法使用代码(特别是 ASP.NET 中的 C#)来执行此操作?
I found the following code to create a tinyurl.com url:
http://tinyurl.com/api-create.php?url=http://myurl.com
This will automatically create a tinyurl url. Is there a way to do this using code, specifically C# in ASP.NET?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可能应该添加一些错误检查等,但这可能是最简单的方法:
You should probably add some error checking, etc, but this is probably the easiest way to do it:
在做了更多研究之后......我偶然发现了以下代码:
看起来它可能可以解决问题。
After doing some more research ... I stumbled upon the following code:
Looks like it may do the trick.
您必须从代码中调用该 URL,然后从服务器读回输出并对其进行处理。
查看 System.Net.WebClient类,DownloadString(或更好:< a href="http://msdn.microsoft.com/en-us/library/system.net.webclient.downloadstringasync.aspx" rel="nofollow noreferrer">DownloadStringAsync) 似乎就是您想要的。
You have to call that URL from your code, then read back the output from the server and process it.
Have a look at the System.Net.WebClient class, DownloadString (or better: DownloadStringAsync) seems to be what you want.
请记住,如果您正在开发一个完整的应用程序,那么您将非常具体地依赖于 TinyURL 的 URL/API 方案。 也许他们保证其 URL 不会更改,但值得一试
Keep in mind if you're doing a full-scale app, that you're wiring in a pretty specific dependency to TinyURL's URL/API scheme. Maybe they have guarantees about their URL not changing, but it's worth checking out
根据此 文章,你可以这样实现:
According to this article, you could implement it like this:
这是我的实现版本:
Here my version of the implementation: