iOS 11.2下HTTP请求失败求助:获取JSON时遇连接错误
Hey there, let's work through this network issue you're hitting. That error code 64 (ENETDOWN) and "Host is down" message tells us your app can't establish a connection to the ECB server at https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml. Here's a step-by-step breakdown to fix this:
First, validate basic network connectivity
- Check if your test device/simulator can access other HTTPS sites (like
https://www.google.com). If you can't reach any sites, the problem is with your device's network setup—double-check Wi-Fi/cellular data is enabled, or if a VPN/proxy is blocking traffic. - Try opening the ECB URL directly in your device's browser. If the browser can't load it either, this points to a network-level issue: either the ECB server is temporarily down, your ISP is blocking the address, or there's a regional restriction preventing access.
- Check if your test device/simulator can access other HTTPS sites (like
Check your app's network configuration
- Verify your
Info.plisthas the correctNSAppTransportSecurity(ATS) settings. Since ECB uses valid HTTPS, the default ATS configuration should work, but if you've added custom exceptions, make sure they aren't interfering with the connection. - If you're using a third-party networking library (like Alamofire), double-check for misconfigured proxies, overly short timeouts, or SSL validation overrides that might be breaking the connection flow.
- Verify your
Test server reachability via terminal
- Run
ping www.ecb.europa.euin your terminal to see if you can get a response from the server. No ping replies mean the server is unreachable from your network. - Use
curl -v https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xmlto get a detailed view of the connection process—this can reveal if the issue is with DNS resolution, SSL handshake, or something else.
- Run
Cross-test across simulator and real device
- If you're using the simulator, switch to a physical device. Simulator network can sometimes conflict with your host machine's settings (like a VPN that's not properly routed to the simulator).
- On a real device, toggle between Wi-Fi and cellular data to rule out issues with one specific network.
Quick side note: You mentioned wanting JSON data—ECB actually provides a JSON version of this feed at https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.json. Once you fix the connection issue, you can use this URL instead if that fits your needs better.
内容的提问来源于stack exchange,提问作者G.Mohr

