今天犯了个低级错误。
在公司内网请求后台数据的时候,将URL的协议头搞混了。
正确做法是:
–外网需要加密签名:所以用的是HTTPS://
–内网不需要加密:所以用HTTP://
而我错误的的就是疏忽未将内网的协议头改成HTTP://
导致所以请求一直收到 finished with error - code: -1002,
修改过来后解决。
还有一种情况:
URL中包含中文或其他特殊字符时,需要转换,建议使用stringByAddingPercentEncodingWithAllowedCharacters API,使用此API时,最好只给参数使用,不要给整个URL使用,比如:
NSString *url = [NSString stringWithFormat:@"%@/users/search/?query=%@", @"http://xxx", [name stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
或者进行UTF-8进行编码