We have answer of your question!

100% solved queries, no empty question

Question: Angular2 http.post does not react on full domain name


0

I have the follwing code:

this.http.post('http://localhost:8080/api/login',
     JSON.stringify({ username, password }),
     { headers }
)

Which does not work, I don't even see an error in the browser console. when using only 'api/login' it works, but of course on the wrong domain. The docu just want an url, is there some CORS issue here or any other restriction Thanks for help?

Question author Torsten | Source

Answer


1


http.post returns an observable, just like any http action does. You need to subscribe on it to make it run.

try this:

this.http.post('http://localhost:8080/api/login',
    { username, password },
    { headers }
).subscribe();

Extra info:

subscribe can take 3 paramaters.

  1. onSuccess(response), called on succes with a response from the server
  2. onError(response), called on error with a response from the server
  3. onComplete, called when the call is completed.

I really suggest you deep into observables

Answer author Robin-dijkhof

Tickanswer.com is providing the only single recommended solution of the question Angular2 http.post does not react on full domain name under the categories i.e angular2 , . Our team of experts filter the best solution for you.

Related Search Queries:

property map does not exist on type observable response ,


You may also add your answer

Thanks for contributing an answer to Tick Answer!