how to fix error “net::ERR_SSL_SERVER_CERT_BAD_FORMAT” When useing vuejs and nodejs with https and express

前端 未结 2 1790
难免孤独
难免孤独 2021-01-27 07:02

I have some code to send https request in vue.js and when use actions methods in vuex for send https request I get this error in console

GET https://loca

相关标签:
2条回答
  • 2021-01-27 07:16

    Taking the certificate PEM shown in the question one can do a openssl x509 -text and see:

    Certificate:
        Data:
            Version: 1 (0x0)
            ...
        Signature Algorithm: sha256WithRSAEncryption
            Issuer: CN=localhost
            ...
            Subject: CN=localhost
    

    Thus, this is a X509v1 certificate issued for localhost. It does not have any Subject Alternative Names extension as required by at least Chrome. Only X509v3 certificates can have such extensions and they need to be specifically configured. The documentation of pem contains examples on how to create certificates with the necessary extensions.

    0 讨论(0)
  • 2021-01-27 07:20

    axios performing a GET request, you should send data in url

    axios.get('/user?ID=12345')
      .then(function (response) {
        // handle success
        console.log(response);
      })
      .catch(function (error) {
        // handle error
        console.log(error);
      })
      .finally(function () {
        // always executed
      })
    

    and performing a POST request

    axios.post('/user', {
        firstName: 'Fred',
        lastName: 'Flintstone'
      })
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      });
    

    now in your code you send POST request and this have object to send, you shod use

    Axios.post('https://localhost:443/api/getpeople',{ withCredentials: 
                 true}).then(response=>response.data).then(result=>{
                       commit('setPeople',result);
                   }).catch(error=>{
                 console.log(error.response)
    

    for GET request

    Axios.get('https://localhost:443/api/getpeople').then(response=>response.data).then(result=>{
                       commit('setPeople',result);
                   }).catch(error=>{
                 console.log(error.response)
    
    0 讨论(0)
提交回复
热议问题