Hi there!
I have local API with self signed SSL certificate.
When I do request by ip on my iOS emulator:
fetch('https://192.168.100.6/users/me')
.then(response => response.json())
.then(json => console.log(json))
.catch(error => console.log(error));
I see next error:
TypeError: Network request failed
at XMLHttpRequest.self.fetch.xhr.onerror (fetch.js:441)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:554)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:387)
at XMLHttpRequest.js:493
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:299)
at MessageQueue.js:111
at MessageQueue.__guard (MessageQueue.js:262)
at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:110)
Also I added certificate to emulator:
When I do request by domain:
fetch('https://api.av.my/users/me')
.then(response => response.json())
.then(json => console.log(json))
.catch(error => console.log(error));
I see the same error:
TypeError: Network request failed
at XMLHttpRequest.self.fetch.xhr.onerror (fetch.js:441)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:554)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:387)
at XMLHttpRequest.js:493
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:299)
at MessageQueue.js:111
at MessageQueue.__guard (MessageQueue.js:262)
at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:110)
I did some digging in the debug I found the error in XMLHttpRequest:
_response: "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “api.av.my” which could put your confidential information at risk."
When I “Enable Network Inspect” then request works nice.
But with “Enable Network Inspect” I can’t do request for file upload:
[RNDebugger] Detected you're enabled Network Inspect and using 'uri' in FormData, it will be a problem if you use it for upload, please see the documentation (https://goo.gl/yEcRrU) for more information.
Eventually I don’t have to test file upload.
System: macOS Hight Sierra 10.13.3
Running application “main” with appParams:
{
"rootTag": 1,
"initialProps": {
"exp": {
"manifest": {
"description": "***",
"privacy": "unlisted",
"logUrl": "http://localhost:19000/logs",
"orientation": "portrait",
"mainModuleName": "node_modules/expo/AppEntry",
"id": "@***",
"developer": {
"projectRoot": "***",
"tool": "xde"
},
"iconUrl": "http://localhost:19001/assets/./src/asset/icon/app-icon.png",
"name": "***",
"sdkVersion": "24.0.0",
"xde": true,
"primaryColor": "#cccccc",
"loading": {
"iconUrl": "http://localhost:19001/assets/./src/asset/icon/app-icon.png",
"icon": "./src/asset/icon/app-icon.png",
"hideExponentText": false
},
"isVerified": true,
"packagerOpts": {
"lanType": "ip",
"minify": false,
"urlRandomness": "ey-jvd",
"hostType": "tunnel",
"strict": false,
"urlType": "exp",
"dev": true
},
"ios": {
"bundleIdentifier": "***",
"supportsTablet": true
},
"bundleUrl": "***",
"android": {
"package": "***"
},
"env": {},
"debuggerHost": "localhost:19001",
"icon": "./src/asset/icon/app-icon.png",
"slug": "***",
"version": "1.0.0"
},
"initialUri": "exp://localhost:19000",
"appOwnership": "expo",
"shell": false
}
}
}