0

I'm trying to do a GET request on an external API. The api gave me a username and password which I encoded to get the Basic Token. When I test in on Postman everything works fine but when implementing it Angular 6 I get a 404 error, which is strange since I used the exact same URL in Postman. This is my code:

this.http.get('https://api.easypost.com/v2/shipments',{
      headers:{
        'Authorization':'Basic '+this.token
      }
    }
  ).subscribe((res:Response)=>{
    console.log(res)
  })

I don't understance why I'm getting a 404. The URL works fine in Postman. This is my networks tab:

Networks Tab

TJ37
  • 35
  • 1
  • 7
  • It seems you're facing a CORS related issue. Notice your "Request Method" is set to "OPTIONS", rather than the intended GET. Either ask the service providers to enable CORS, or run the GET request on you server side rather than client side to circumvent this issue. – Mo A Jan 27 '19 at 20:19
  • im getting the 404 error before getting the cors error, the 404 is causing the cors issue. The access-allow-origin is allowed on the server since its an external api and they want you to access it. The problem has something to do with the location of the token. – TJ37 Jan 27 '19 at 21:03
  • This might be useful - https://stackoverflow.com/questions/48413485/calling-easypost-api-from-browser-client-javascript – Mo A Jan 27 '19 at 21:14
  • Yeah I solved it, just needed to use a proxy server! Thankx – TJ37 Jan 28 '19 at 03:21

0 Answers0