1
我有这个网址,我试图通过bit.ly API缩短网址。这里是我的代码缩短包含&参数的网址
NSString *url = @"http://www.example.com&username=abc&password=123&mode=offline";
NSString *requestStr = [NSString stringWithFormat:@"http://api.bit.ly/v3/shorten?login=%@&apiKey=%@&longUrl=%@&format=txt",login, api_key, url];
requestStr = [requestStr stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:requestStr]];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *response = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
我得到响应的URL对应唯一http://www.example.com
出人意料的是,&用户名= ABC &密码= 123 &模式= URL的离线部分进行修剪。 只有当我通过xcode进行时才会发生这种情况。在网站上,它工作正常。请帮忙。