网络请求失败:Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSUnderlyingError=0x7ff218465150 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "The network connection was lost." UserInfo={NSErrorFailingURLStringKey=http://192.168.1.89:8888/shihai_snatch/v1/u/userBuyList, NSErrorFailingURLKey=http://192.168.1.89:8888/shihai_snatch/v1/u/userBuyList, _kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4, NSLocalizedDescription=The network connection was lost.}}, NSErrorFailingURLStringKey=http://192.168.1.89:8888/shihai_snatch/v1/u/userBuyList, NSErrorFailingURLKey=http://192.168.1.89:8888/shihai_snatch/v1/u/userBuyList, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSLocalizedDescription=The network connection was lost.}
经常出现这种情况 请问怎么解决
It looks like the network is down...or the server is shut down...
There are two special characters ":" in your URL. The first ":" can be recognized normally, and the second ":" is the port number and cannot be recognized normally, so the URL reported is illegal. mistake.
There are some differences between accessing the URL in iOS and direct access from the browser. The browser will encode the URL with special characters when requesting it. However, when developing iOS, you need to encode it yourself. There are ready-made methods for NSString encoding, as follows
Please encode the NSString address before assembling NSURL.
This will convert the special characters
!*'();:@&=+$,/?%#[]
in the URL into the corresponding % format encoding, so that normal requests can be made.Hope it helps and wish you good luck.