IssueRaiser

HTTP Fetch fails with "TypeError: Network request failed" => Resolved

### Description There are 83 issues opened and unanswered about network requests failing with this generic error. The main causes of the pain are: 1. Not getting an answer from the team 2. The exception is far too generic and does not suggest the origin of the problem ### Problem description Using `fetch` to get/post on a HTTPS web server which is using a valid and trusted but **not public** CA. - Using Chrome and other apps the requests are always successful and without certificate problems Sample code in react native: ``` static async Post(): Promise<string> { let srv = "my.domain.com"; let port = 5101; let device = "abcd"; let url = `https://${srv}:${port}/Do/Something?devicename=${device}`; try { let response = await fetch(url, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-type':'application/json' }, body: JSON.stringify({ key: 'value', }) }); if(response.status !== 200) throw new Error(`Can't open ${srv} for ${device} with status ${response.status}`); return response.json(); } catch(e) { console.log(e); throw(e); } } ``` ### Solution Due to Android restrictions, a `network_security_config` configuration must be added to the application. It is an xml file that can be added by following these steps: 1. Edit the `android/app/src/main/AndroidManifest.xml` 2. Ad

Posted by raffaeler on Jan 20, 2022, 10:53 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

github (SaaS)

HTTP Fetch fails with "TypeError: Network request failed" => Resolved

raffaelerJan 20, 2022, 10:53 AM

### Description There are 83 issues opened and unanswered about network requests failing with this generic error. The main causes of the pain are: 1. Not getting an answer from the team 2. The exception is far too generic and does not suggest the origin of the problem ### Problem description Using `fetch` to get/post on a HTTPS web server which is using a valid and trusted but **not public** CA. - Using Chrome and other apps the requests are always successful and without certificate problems Sample code in react native: ``` static async Post(): Promise<string> { let srv = "my.domain.com"; let port = 5101; let device = "abcd"; let url = `https://${srv}:${port}/Do/Something?devicename=${device}`; try { let response = await fetch(url, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-type':'application/json' }, body: JSON.stringify({ key: 'value', }) }); if(response.status !== 200) throw new Error(`Can't open ${srv} for ${device} with status ${response.status}`); return response.json(); } catch(e) { console.log(e); throw(e); } } ``` ### Solution Due to Android restrictions, a `network_security_config` configuration must be added to the application. It is an xml file that can be added by following these steps: 1. Edit the `android/app/src/main/AndroidManifest.xml` 2. Ad

Comments (0)

No comments yet. Start the discussion.

Comment on this issue