Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
Javascript auth similar to Python auth?

I am trying to get data from a rest api call and with python request and it is working. How can I do similar in JavaScript and Typescript? I will need it in my Angular2 application.

Working Python script import requests

url = "restapi"

r = requests.post(url,  auth=('user', 'password'))
print(r.text)
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need to use http (provided with RxJS)

Your import:

import { Http } from '@angular/http';

Injected in your constructor:

constructor(public http: Http) {}

Your rest request method:

login(user:User,onNext: (response) => void) {
    this.http
        .post(BASE_URL+"/login",user)
        .map(response => response.json())
        .subscribe(onNext,(e)=> console.error(`${e}`));
}

Note1: User is a typed json with just {user:string, password:string}

Note2: Please consider to do all the above in a @Injectable() Provider/Service, and the next step in your component (for beginning you can make everything in the same class)

Then use it like this

login(myUserJson,(result)=>{
     console.log(result);
     //proceed!...
})
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda