我开始研究node js,并尝试将ionic应用程序与我创建的后端nodejs应用程序连接,但我收到此错误消息:
OPTIONS https://localhost:3000/insert net :: 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)
});
答案 0 :(得分:1)
端口3000通常用于纯HTTP而非HTTPS,这在您的设置中也可能适用。如果您在URL中使用https://
而不是http://
,它不会神奇地变成HTTPS。
错误消息是由于您的客户端使用了错误的协议(HTTPS,即基于TLS的HTTP)而导致的,并且来自服务器的答案(纯HTTP,不带TLS)不是客户端期望的有效TLS消息-即ERR_SSL_PROTOCOL_ERROR
。
`