Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

979
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda