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

980
Visualizações
Convert CURL request to Angular 2 HTTP get request

I want to get access to the data on wp woocommerce via rest api. I was trying to get data with curl and it's working. curl https://${sec_key}:${customer_secret}@exmpl.com/wp-json/wc/v1/orders, but now I need to get access with Angular 2 http service. is't possible?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

When you put the username and password in the URL like this

https://${sec_key}:${customer_secret}@exmpl.com

it is behind the scenes just doing Basic Authentication, which is basically just a Authorization header with the following value

Authorization: base64(username:password)

Here, base64 is just some arbitrary function that base-64 encodes username:password; that's the username and password separated with a colon. In Javascript, there is the global btoa function that will base-64 encode the string for you.

So in Angular, you can do

const headers = new Headers({
  'Authorization': btoa(secKey, custSecret)
})
http.get(url, { headers: headers })

But here's the problem. You are exposing (I'm assuming) you secret information to the client, which you should never do. Another thing, you need to make sure that the API even allows to send the is request from Javascript clients. Some APIs, especially ones where there is sensitive information being passed around, won't allow for direct Javascript (client-side) communication. They do this by not allowing Cross Origin requests.

So you need to make sure that the API even accepts Cross Origin requests from client side applications, and secondly you need to consider the implications of using your secret in the client application.

I've never used Woocommerce, and I have no idea what it even is. But if it has to do with commerce, I might assume that it is meant to be connected to server to server. This is something you should consider, or maybe even something that you have to do. So you would basically from your client app communicate with your server app, which would then communicate with the API.

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