shorten URL

原文出处: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];
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
问题"Failed to retrieve application JMX service URL"通常是由于一些配置或环境问题导致的。根据引用内容,有几种可能的解决方案可以尝试: 1. 取消启用JMX代理: 在IDEA中选择项目,然后选择Spring Boot插件。在启动项目的配置中,找到"Enable JMX agent"选项,并取消选中该选项。重新启动项目,看看是否还会出现错误。 2. 修改JRE配置: 在启动配置中,选择一个本地的JRE作为项目的运行环境。同时,可以尝试调整"shorten command line"选项,选择将长类路径写入文本文件中。保存配置并重新启动项目。 3. 关闭可能导致冲突的程序: 有时候,一些其他的程序可能会影响到IDEA中的Spring Boot项目的启动。例如,引用提到了金山词霸识词翻译导致的问题。在这种情况下,退出或关闭可能导致冲突的程序,然后重新启动项目,看看问题是否解决。 需要注意的是,以上解决方案都是基于已提供的引用内容,具体的解决方法可能因实际情况而异。建议根据自己的具体情况尝试这些解决方案,并确保项目的配置和环境是正确的。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [IDEA报错:Failed to retrieve application JMX service URL(无法检索应用程序JMX服务URL)](https://blog.csdn.net/weixin_48255731/article/details/129347700)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Failed to retrieve application JMX service URL](https://blog.csdn.net/wodezuiaidxp/article/details/102912851)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值