node.js - 当我尝试连接本地主机时出现 ERR_SSL_PROTOCOL_ERROR

标签 node.js ssl ionic-framework localhost

我开始研究 Node js,我正在尝试将 ionic 应用程序与我创建的后端 nodejs 应用程序连接,但我收到此错误:

选项 https://localhost:3000/insert净::ERR_SSL_PROTOCOL_ERROR

import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { map } from 'rxjs/operators';

@Component({
  selector: 'app-cadastro-unidade',
  templateUrl: './cadastro-unidade.page.html',
  styleUrls: ['./cadastro-unidade.page.scss'],
})

export class CadastroUnidadePage implements OnInit {

  constructor(private http: Http) { }

  ngOnInit() {

  } 

  InsereDados(){
    let data = {
    };

    this.http.post('https://localhost:3000/insert', data).pipe(
            map(res => res.json())
        ).subscribe(response => {
            console.log('POST Response:', response);
        });
  }

}

app.get('/insert', function(req, res, next) {
var uri = "xxxx"
    MongoClient.connect(uri,{ useNewUrlParser: true }, function(err,client){const collection = client.db("test").collection("teste");
    console.log("connected");

    var ins={DataEntrada:"x",DataSaida:"x",HorarioEntrada:"x",HorarioSaida:"x",Prontuario:"x",TipoSaida:"x"};

    collection.insertOne(ins, function(err,res){
      console.log("data inserted");

    })

    client.close();
    })
    res.render(res)
});

最佳答案

端口 3000 通常用于纯 HTTP 而不是 HTTPS,这在您的设置中也可能是正确的。如果您在 URL 中使用 https:// 而不是 http://,它不会神奇地变成 HTTPS。

错误消息是由于您的客户端使用了错误的协议(protocol)(HTTPS,即基于 TLS 的 HTTP)以及来自服务器的应答(普通 HTTP,没有 TLS)不是客户端所期望的有效 TLS 消息的结果- 即 ERR_SSL_PROTOCOL_ERROR

`

关于node.js - 当我尝试连接本地主机时出现 ERR_SSL_PROTOCOL_ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58003508/

相关文章:

node.js - Mongoose 模式中的 `required`是什么意思?

python - 在 Python 中使用 SSL 和身份验证运行 GET

mysql --ssl-verify-server-cert=true 返回 "SSL certificate validation failure"

python - python ssl 库中的 ssl.SSLError : [SSL] PEM lib (_ssl. c:3833)

javascript - TextBoxes 不会获得焦点

javascript - 应用程序可以在浏览器上运行,但不能在设备上运行 CORS 问题?无网络事件

html - ionic 复选框高度不成比例

javascript - nodejs中如何保证Knex连接

javascript - 在 Eclipse 中重构 Javascript "extract method"导致崩溃

javascript - 在数组中查找重复对