由于业务需要,要控制不同移动端和不同版本的api请求。
直接将版本控制的信息加入到BaseURL,类似:
结果总是出现Not Found。
通过抓包工具Charles发现请求的url不正确,只保留了BaseUrl的域名和Path的拼接。path如下:
网上找了很多文章,好多都没Get到点,后面在一篇文章中看到AFNetworking的发现了问题
解决AFNetworking封装baseUrl后接内容被忽略
在AFHTTPSessionManager的头文件发现如下的解释:
代码如下:
Below are a few examples of how `baseURL` and relative paths interact:
NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"];
[NSURL URLWithString:@"foo" relativeToURL:baseURL]; //http://example.com/v1/foo
[NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL]; //http://example.com/v1/foo?bar=baz
[NSURL URLWithString:@"/foo" relativeToURL:baseURL]; //http://example.com/foo
[NSURL URLWithString:@"foo/" relativeToURL:baseURL]; //http://example.com/v1/foo
[NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; //http://example.com/foo/
[NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; //http://example2.com/
最后的最后,将BaseUrl修改如下:
Path如下:
Thanks God!
终于可以了~