1.AFN baseurl出错
baseurl最后必须以 / 结束;
NSString *loginString = @"app/login";
NSURL *baseUrl = [NSURL URLWithString:@"http://192.12.12:8080/lyzh/"];
NSString *resultUrl = [[NSURL URLWithString:loginString relativeToURL:baseUrl] absoluteString];
NSLog(@"resultUrl=%@",resultUrl);
打印结果:resultUrl=http://192.12.12:8080/lyzh/app/login
NSString *loginString = @"/app/login";
NSURL *baseUrl = [NSURL URLWithString:@"http://192.12.12:8080/lyzh"];
NSString *resultUrl = [[NSURL URLWithString:loginString relativeToURL:baseUrl] absoluteString];
NSLog(@"resultUrl=%@",resultUrl);
打印结果:resultUrl=http://192.12.12:8080/app/login
结论:baseurl最后一个 / 之后的内容会被忽略掉,定义AFN baseurl时,必须以 / 结束;
网友评论