shorten URL
来源:互联网 发布:广州市梦享网络 编辑:程序博客网 时间:2024/06/05 00:13
原文出处:http://pelz-sherman.net/blog/2009/05/16/url-shortening-in-objective-c/
Here’s a little class I wrote this weekend to support URL shortening using the is.gd service.
I hope someone finds it useful.
// URLShortener.h
#import
@interface URLShortener : NSObject {}
+ (NSString *)shortURL:(NSString *)longURL;
@end
=================================
//
// URLShortener.m
// Creates a short URL from a long URL using the is.gd API.
/
#import "URLShortener.h"
@implementation URLShortener
+ (NSString *)shortURL:(NSString *)longURL {
NSURL *apiURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://is.gd/api.php?longurl=%@",longURL]];
NSError *error = nil;
NSString *result = [NSString stringWithContentsOfURL:apiURL encoding:NSISOLatin2StringEncoding error:&error];
if (error != nil) {
NSLog([error description]);
return nil;
} else {
return result;
}
}
@end
原文:http://uplink.to/home/support/uplink-to-web-service/url-shortening/
方法2:Shorten any URL over at uplink.to Calling http://uplink.to/uplinkto.php?longurl={escaped URL string} from any language will return the shortened URL in the http response. Here is an example in Cocoa:
-(NSString*)shortenURL:(NSString*)url{ CFStringRef legalStr = CFSTR("!@#$%^&()<>?{},;'[]"); NSString *escUrl = (NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)url, NULL, legalStr, kCFStringEncodingUTF8); NSString *apiEndpoint = [NSString stringWithFormat:@"http://uplink.to/uplinkto.php?longurl=%@",escUrl]; NSError* error; NSString* shortURL = [NSString stringWithContentsOfURL:[NSURL URLWithString:apiEndpoint] encoding:NSASCIIStringEncoding error:&error]; if (shortURL) return shortURL; else return [error localizedDescription];}
- shorten URL
- Programming Interview Questions 111: Design url shorten system
- google shorten api
- 22 Open Source PHP Frameworks To Shorten Your Development Time
- 【jzoj5360】【NOIP2017提高A组模拟9.12】【Shorten Diameter】
- JZOJ5360. 【NOIP2017提高A组模拟9.12】Shorten Diameter
- 【NOIP2017提高A组模拟9.12】Shorten Diameter
- url
- URL
- URL
- url
- url
- URL
- url
- URL
- url
- url
- url
- COL命令用法
- JQuery 禁用所有select标签的值
- Java程序设计(九)----模拟用户帐户的程序
- 由浅入深 Core Data 详解
- Qt Model/View Framework学习
- shorten URL
- hadoop伪分布式的配置
- 问心无愧的伤感爱情日志分享:我爱你,到底值不值得
- 使用/proc文件系统和内核打交道(2)-确定系统的CPU情况
- 使用MultiView 与View 单击不同的Linkbutton,显示不同领域的内容
- 方法中的内部类能不能访问方法中的局部变量,为什么
- 如何让google,baidu,Yahoo收录你的网站
- 解决控件只能在本地运行,不能在服务器上运行
- Linux系统时间设置(附ARM)