之前的旧项目,把功能模块移植到另一个应用中,结果在图片加载的时候,始终加载不到图片,然后一路追查,查到了拼接的图片地址上面,打印图片地址发下http://协议头少了个“/” , 项目中都是这样使用
stringByAppendingPathComponent:
拼接的网络地址,POST网络请求也没问题。唯独使用SDWebimage 进行图片加载时失败 ,因为协议头少了个 / 。(猜测
stringByAppendingPathComponent:方法是会进行以单 / 替换字符串中连在一起的多个 // )
NSString *testStr = @"https://123.21.54.1/health/uiiddd/3323";
NSString *str = [testStr stringByAppendingString:@"/justtry"];
NSString *comStr = [testStr stringByAppendingPathComponent:@"justtry"];
NSLog(@"===%@",str);
NSLog(@"===%@",comStr);
NSString *comStr2 = [testStr stringByAppendingPathComponent:@"///justtry"];
NSLog(@"===%@",comStr2);
打印结果:
2017-11-24 14:19:48.607 Switch[59129:2841826] ===https://123.21.54.1/health/uiiddd/3323/justtry
2017-11-24 14:19:48.608 Switch[59129:2841826] ===https:/123.21.54.1/health/uiiddd/3323/justtry
2017-11-24 14:33:38.935 Switch[59409:2855959] ===https:/123.21.54.1/health/uiiddd/3323/justtry