How to disable ssl check in react native XMLHttpRequest API or in Fetch Api?

人走茶凉 提交于 2021-02-04 18:53:11

问题


On local testing server url have ssl certificate error so i have to disable ssl check. I have read many solutions on stackoverflow none of them helped. Problem is i can't make any change on server. So i want to know how to disable ssl check or is there any other api like fetch api or Retrofit for react native.?
My fetch api code as follows

fetch('https://example.com/logincheck', {
  method: 'post',
  headers: {
    'Accept': 'application/json, text/plain,',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "username" :"usrname",
  })
})
  .then(response =>  response.json())
  .then(responseobj => {
    this.setState({

    });
    console.log("login status:",responseobj.success);


  })
  .catch((error) => {
      console.error(error);
    });

回答1:


Now to bypass ssl certificate issue.. rn-fetch-blob released. Anyone searching for updated answer please use this answer and check the

rn-fetch-blob

package. To connect a server with self-signed certification, you need to add trusty to config explicitly

RNFetchBlob.config({
  trusty : true
})
.fetch('GET', 'https://example.com')
.then((resp) => {
  // ...
})



回答2:


I think you are using self signed certificate that's why this problem so instead of self certificate use free ssl refer the following link for further information

self-signed certificate

I'm not suggesting disable the ssl check because this is not a good practice. So please suggest administrator to change self certificate to free ssl. I think you got the answer.



来源:https://stackoverflow.com/questions/51130878/how-to-disable-ssl-check-in-react-native-xmlhttprequest-api-or-in-fetch-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!