Cannot send request with React Native and Axios












0















I've read dozens of answers, and I can't seem to figure this out:




  • The request works fine in iOS, but it does not work in Android

  • I am using React Native 0.57.5 and axios 0.18.0

  • I put some logging via



axios.interceptors.request.use(request => {
console.log('Starting Request', request)
return request
})

axios.interceptors.response.use(response => {
console.log('Response:', response)
return response
})



enter image description here



As it can be seen, the request seems fine. And it is not towards localhost but to an actual, running server (I redacted some internal header keys and the full URLs)




  • Also put a log statement to catch of where I make my axios request:



axios.request(config)
.then((axiosResponse) => {
console.log('GOOD RESPONSE ', axiosResponse)

// some logic
})
.catch((error) => {
console.log('axiosResponse ERROR', error)
// some other logic
})



And this is what I see in the chrome debugger console:




axiosResponse ERROR Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:87)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:580)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
at XMLHttpRequest.js:507
at RCTDeviceEventEmitter.emit (EventEmitter.js:190)
at MessageQueue.__callFunction (MessageQueue.js:349)
at MessageQueue.js:106
at MessageQueue.__guard (MessageQueue.js:297)
at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:105)
at debuggerWorker.js:72



This is part of my upgrade from React Native 0.55.0 to 0.57.5, so this axios stuff was working normally before.



Any ideas?










share|improve this question



























    0















    I've read dozens of answers, and I can't seem to figure this out:




    • The request works fine in iOS, but it does not work in Android

    • I am using React Native 0.57.5 and axios 0.18.0

    • I put some logging via



    axios.interceptors.request.use(request => {
    console.log('Starting Request', request)
    return request
    })

    axios.interceptors.response.use(response => {
    console.log('Response:', response)
    return response
    })



    enter image description here



    As it can be seen, the request seems fine. And it is not towards localhost but to an actual, running server (I redacted some internal header keys and the full URLs)




    • Also put a log statement to catch of where I make my axios request:



    axios.request(config)
    .then((axiosResponse) => {
    console.log('GOOD RESPONSE ', axiosResponse)

    // some logic
    })
    .catch((error) => {
    console.log('axiosResponse ERROR', error)
    // some other logic
    })



    And this is what I see in the chrome debugger console:




    axiosResponse ERROR Error: Network Error
    at createError (createError.js:16)
    at XMLHttpRequest.handleError (xhr.js:87)
    at XMLHttpRequest.dispatchEvent (event-target.js:172)
    at XMLHttpRequest.setReadyState (XMLHttpRequest.js:580)
    at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
    at XMLHttpRequest.js:507
    at RCTDeviceEventEmitter.emit (EventEmitter.js:190)
    at MessageQueue.__callFunction (MessageQueue.js:349)
    at MessageQueue.js:106
    at MessageQueue.__guard (MessageQueue.js:297)
    at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:105)
    at debuggerWorker.js:72



    This is part of my upgrade from React Native 0.55.0 to 0.57.5, so this axios stuff was working normally before.



    Any ideas?










    share|improve this question

























      0












      0








      0








      I've read dozens of answers, and I can't seem to figure this out:




      • The request works fine in iOS, but it does not work in Android

      • I am using React Native 0.57.5 and axios 0.18.0

      • I put some logging via



      axios.interceptors.request.use(request => {
      console.log('Starting Request', request)
      return request
      })

      axios.interceptors.response.use(response => {
      console.log('Response:', response)
      return response
      })



      enter image description here



      As it can be seen, the request seems fine. And it is not towards localhost but to an actual, running server (I redacted some internal header keys and the full URLs)




      • Also put a log statement to catch of where I make my axios request:



      axios.request(config)
      .then((axiosResponse) => {
      console.log('GOOD RESPONSE ', axiosResponse)

      // some logic
      })
      .catch((error) => {
      console.log('axiosResponse ERROR', error)
      // some other logic
      })



      And this is what I see in the chrome debugger console:




      axiosResponse ERROR Error: Network Error
      at createError (createError.js:16)
      at XMLHttpRequest.handleError (xhr.js:87)
      at XMLHttpRequest.dispatchEvent (event-target.js:172)
      at XMLHttpRequest.setReadyState (XMLHttpRequest.js:580)
      at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
      at XMLHttpRequest.js:507
      at RCTDeviceEventEmitter.emit (EventEmitter.js:190)
      at MessageQueue.__callFunction (MessageQueue.js:349)
      at MessageQueue.js:106
      at MessageQueue.__guard (MessageQueue.js:297)
      at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:105)
      at debuggerWorker.js:72



      This is part of my upgrade from React Native 0.55.0 to 0.57.5, so this axios stuff was working normally before.



      Any ideas?










      share|improve this question














      I've read dozens of answers, and I can't seem to figure this out:




      • The request works fine in iOS, but it does not work in Android

      • I am using React Native 0.57.5 and axios 0.18.0

      • I put some logging via



      axios.interceptors.request.use(request => {
      console.log('Starting Request', request)
      return request
      })

      axios.interceptors.response.use(response => {
      console.log('Response:', response)
      return response
      })



      enter image description here



      As it can be seen, the request seems fine. And it is not towards localhost but to an actual, running server (I redacted some internal header keys and the full URLs)




      • Also put a log statement to catch of where I make my axios request:



      axios.request(config)
      .then((axiosResponse) => {
      console.log('GOOD RESPONSE ', axiosResponse)

      // some logic
      })
      .catch((error) => {
      console.log('axiosResponse ERROR', error)
      // some other logic
      })



      And this is what I see in the chrome debugger console:




      axiosResponse ERROR Error: Network Error
      at createError (createError.js:16)
      at XMLHttpRequest.handleError (xhr.js:87)
      at XMLHttpRequest.dispatchEvent (event-target.js:172)
      at XMLHttpRequest.setReadyState (XMLHttpRequest.js:580)
      at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
      at XMLHttpRequest.js:507
      at RCTDeviceEventEmitter.emit (EventEmitter.js:190)
      at MessageQueue.__callFunction (MessageQueue.js:349)
      at MessageQueue.js:106
      at MessageQueue.__guard (MessageQueue.js:297)
      at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:105)
      at debuggerWorker.js:72



      This is part of my upgrade from React Native 0.55.0 to 0.57.5, so this axios stuff was working normally before.



      Any ideas?







      react-native axios react-native-android






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 21:23









      kolistivrakolistivra

      1,86053244




      1,86053244
























          1 Answer
          1






          active

          oldest

          votes


















          1














          For what you said I think it must be that you didn't ask for internet permissions, if that's the case you need to edit in your android project inside react your manifest file it must be in $your_project_root_directory/android/app/src/main/AndroidManifest.xml



          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="your.package"
          android:versionCode="1"
          android:versionName="1.0">
          ...
          <uses-permission android:name="android.permission.INTERNET" />
          ...
          </manifest>


          Other thing that could be is that if you are using http connection. try the following



          <network-security-config>
          <domain-config cleartextTrafficPermitted="true">
          <domain includeSubdomains="true">yourinsecureserver.com</domain>
          </domain-config>
          </network-security-config>

          <?xml version="1.0" encoding="utf-8"?>
          <manifest ... >
          <application android:networkSecurityConfig="@xml/network_security_config"
          ... >
          ...
          </application>
          </manifest>


          https://android-developers.googleblog.com/2018/04/protecting-users-with-tls-by-default-in.html






          share|improve this answer


























          • Unfortunately, that's not the case. I see <uses-permission android:name="android.permission.INTERNET" /> right there in my AndroidManifest.xml. And as I said, this started happening as part of my effort to upgrade react native

            – kolistivra
            Nov 22 '18 at 2:52






          • 1





            Are you able to browse normally from the device?

            – Cristian Gomez
            Nov 22 '18 at 2:54











          • Is your url https or http? android-developers.googleblog.com/2018/04/…

            – Cristian Gomez
            Nov 22 '18 at 3:00











          • I am an idiot -- I fixed the internet connection and now it works! stackoverflow.com/questions/44535500/… Many thanks!

            – kolistivra
            Nov 22 '18 at 3:24













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420647%2fcannot-send-request-with-react-native-and-axios%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          For what you said I think it must be that you didn't ask for internet permissions, if that's the case you need to edit in your android project inside react your manifest file it must be in $your_project_root_directory/android/app/src/main/AndroidManifest.xml



          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="your.package"
          android:versionCode="1"
          android:versionName="1.0">
          ...
          <uses-permission android:name="android.permission.INTERNET" />
          ...
          </manifest>


          Other thing that could be is that if you are using http connection. try the following



          <network-security-config>
          <domain-config cleartextTrafficPermitted="true">
          <domain includeSubdomains="true">yourinsecureserver.com</domain>
          </domain-config>
          </network-security-config>

          <?xml version="1.0" encoding="utf-8"?>
          <manifest ... >
          <application android:networkSecurityConfig="@xml/network_security_config"
          ... >
          ...
          </application>
          </manifest>


          https://android-developers.googleblog.com/2018/04/protecting-users-with-tls-by-default-in.html






          share|improve this answer


























          • Unfortunately, that's not the case. I see <uses-permission android:name="android.permission.INTERNET" /> right there in my AndroidManifest.xml. And as I said, this started happening as part of my effort to upgrade react native

            – kolistivra
            Nov 22 '18 at 2:52






          • 1





            Are you able to browse normally from the device?

            – Cristian Gomez
            Nov 22 '18 at 2:54











          • Is your url https or http? android-developers.googleblog.com/2018/04/…

            – Cristian Gomez
            Nov 22 '18 at 3:00











          • I am an idiot -- I fixed the internet connection and now it works! stackoverflow.com/questions/44535500/… Many thanks!

            – kolistivra
            Nov 22 '18 at 3:24


















          1














          For what you said I think it must be that you didn't ask for internet permissions, if that's the case you need to edit in your android project inside react your manifest file it must be in $your_project_root_directory/android/app/src/main/AndroidManifest.xml



          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="your.package"
          android:versionCode="1"
          android:versionName="1.0">
          ...
          <uses-permission android:name="android.permission.INTERNET" />
          ...
          </manifest>


          Other thing that could be is that if you are using http connection. try the following



          <network-security-config>
          <domain-config cleartextTrafficPermitted="true">
          <domain includeSubdomains="true">yourinsecureserver.com</domain>
          </domain-config>
          </network-security-config>

          <?xml version="1.0" encoding="utf-8"?>
          <manifest ... >
          <application android:networkSecurityConfig="@xml/network_security_config"
          ... >
          ...
          </application>
          </manifest>


          https://android-developers.googleblog.com/2018/04/protecting-users-with-tls-by-default-in.html






          share|improve this answer


























          • Unfortunately, that's not the case. I see <uses-permission android:name="android.permission.INTERNET" /> right there in my AndroidManifest.xml. And as I said, this started happening as part of my effort to upgrade react native

            – kolistivra
            Nov 22 '18 at 2:52






          • 1





            Are you able to browse normally from the device?

            – Cristian Gomez
            Nov 22 '18 at 2:54











          • Is your url https or http? android-developers.googleblog.com/2018/04/…

            – Cristian Gomez
            Nov 22 '18 at 3:00











          • I am an idiot -- I fixed the internet connection and now it works! stackoverflow.com/questions/44535500/… Many thanks!

            – kolistivra
            Nov 22 '18 at 3:24
















          1












          1








          1







          For what you said I think it must be that you didn't ask for internet permissions, if that's the case you need to edit in your android project inside react your manifest file it must be in $your_project_root_directory/android/app/src/main/AndroidManifest.xml



          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="your.package"
          android:versionCode="1"
          android:versionName="1.0">
          ...
          <uses-permission android:name="android.permission.INTERNET" />
          ...
          </manifest>


          Other thing that could be is that if you are using http connection. try the following



          <network-security-config>
          <domain-config cleartextTrafficPermitted="true">
          <domain includeSubdomains="true">yourinsecureserver.com</domain>
          </domain-config>
          </network-security-config>

          <?xml version="1.0" encoding="utf-8"?>
          <manifest ... >
          <application android:networkSecurityConfig="@xml/network_security_config"
          ... >
          ...
          </application>
          </manifest>


          https://android-developers.googleblog.com/2018/04/protecting-users-with-tls-by-default-in.html






          share|improve this answer















          For what you said I think it must be that you didn't ask for internet permissions, if that's the case you need to edit in your android project inside react your manifest file it must be in $your_project_root_directory/android/app/src/main/AndroidManifest.xml



          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="your.package"
          android:versionCode="1"
          android:versionName="1.0">
          ...
          <uses-permission android:name="android.permission.INTERNET" />
          ...
          </manifest>


          Other thing that could be is that if you are using http connection. try the following



          <network-security-config>
          <domain-config cleartextTrafficPermitted="true">
          <domain includeSubdomains="true">yourinsecureserver.com</domain>
          </domain-config>
          </network-security-config>

          <?xml version="1.0" encoding="utf-8"?>
          <manifest ... >
          <application android:networkSecurityConfig="@xml/network_security_config"
          ... >
          ...
          </application>
          </manifest>


          https://android-developers.googleblog.com/2018/04/protecting-users-with-tls-by-default-in.html







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 '18 at 3:02

























          answered Nov 22 '18 at 2:11









          Cristian GomezCristian Gomez

          1,43821026




          1,43821026













          • Unfortunately, that's not the case. I see <uses-permission android:name="android.permission.INTERNET" /> right there in my AndroidManifest.xml. And as I said, this started happening as part of my effort to upgrade react native

            – kolistivra
            Nov 22 '18 at 2:52






          • 1





            Are you able to browse normally from the device?

            – Cristian Gomez
            Nov 22 '18 at 2:54











          • Is your url https or http? android-developers.googleblog.com/2018/04/…

            – Cristian Gomez
            Nov 22 '18 at 3:00











          • I am an idiot -- I fixed the internet connection and now it works! stackoverflow.com/questions/44535500/… Many thanks!

            – kolistivra
            Nov 22 '18 at 3:24





















          • Unfortunately, that's not the case. I see <uses-permission android:name="android.permission.INTERNET" /> right there in my AndroidManifest.xml. And as I said, this started happening as part of my effort to upgrade react native

            – kolistivra
            Nov 22 '18 at 2:52






          • 1





            Are you able to browse normally from the device?

            – Cristian Gomez
            Nov 22 '18 at 2:54











          • Is your url https or http? android-developers.googleblog.com/2018/04/…

            – Cristian Gomez
            Nov 22 '18 at 3:00











          • I am an idiot -- I fixed the internet connection and now it works! stackoverflow.com/questions/44535500/… Many thanks!

            – kolistivra
            Nov 22 '18 at 3:24



















          Unfortunately, that's not the case. I see <uses-permission android:name="android.permission.INTERNET" /> right there in my AndroidManifest.xml. And as I said, this started happening as part of my effort to upgrade react native

          – kolistivra
          Nov 22 '18 at 2:52





          Unfortunately, that's not the case. I see <uses-permission android:name="android.permission.INTERNET" /> right there in my AndroidManifest.xml. And as I said, this started happening as part of my effort to upgrade react native

          – kolistivra
          Nov 22 '18 at 2:52




          1




          1





          Are you able to browse normally from the device?

          – Cristian Gomez
          Nov 22 '18 at 2:54





          Are you able to browse normally from the device?

          – Cristian Gomez
          Nov 22 '18 at 2:54













          Is your url https or http? android-developers.googleblog.com/2018/04/…

          – Cristian Gomez
          Nov 22 '18 at 3:00





          Is your url https or http? android-developers.googleblog.com/2018/04/…

          – Cristian Gomez
          Nov 22 '18 at 3:00













          I am an idiot -- I fixed the internet connection and now it works! stackoverflow.com/questions/44535500/… Many thanks!

          – kolistivra
          Nov 22 '18 at 3:24







          I am an idiot -- I fixed the internet connection and now it works! stackoverflow.com/questions/44535500/… Many thanks!

          – kolistivra
          Nov 22 '18 at 3:24






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420647%2fcannot-send-request-with-react-native-and-axios%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          If I really need a card on my start hand, how many mulligans make sense? [duplicate]

          Alcedinidae

          Can an atomic nucleus contain both particles and antiparticles? [duplicate]