我开始研究 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/