Muhammad Mudassir
Muhammad Mudassir

Reputation: 331

How to receive GET request in an Angular page?

I'm developing Angular app where user opens a URL (https://localhost:4200/bookingDone) fills the forms.

After that user clicks on PAY button and a POST request is fired to server to payment gate way with this

postBackURL: 'https://localhost:4200/oilChanger'

After creation of token on server. Server fires a GET call back to my angular app using url provided in postBackURL. How can I handle is call and route the UI to the oilChanger. I get this error in console:

GET https://localhost:4200/oilChanger?auth_token=1876038377738301950287234324&postBackURL=https%3A%2F%2Flocalhost%3A4200%2FoilChanger 0 ()

core.js:1350 ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}

Now problem is that my corresponding Angular Page that I configured for that Callback URL is not opening. I configured /oilChanger page in RouteProvider, but that seems not to be working.

However, if I open the url directly via browser, it gets opened. my http call:

this.http.post('https://abcd.com/Index.jsf', body.toString(), options).subscribe(response => {
      console.log(response)
    });

How this scenario can be handled? Any help would be greatly appreciated.

Upvotes: 0

Views: 1919

Answers (1)

Quentin
Quentin

Reputation: 944210

How to receive GET request in an AngularJS page?

You can't.

Angular is a client-side JavaScript framework.

HTTP requests are received by servers, not clients.


  1. You need to run an HTTP server (you need one to deliver the Angular app to clients anyway).
  2. You need to use a postBackURL that the service you are using can use to access that server. localhost means "This computer" and the service making the postback request will have a different idea about what "this computer" is to your web browser.
  3. You need to handle the postback request on your HTTP server. How you do that will depend on what you want to do with the information in the request. If you need to get it back to Angular, then you'll probably want to also set up a WebSocket connection between your Angular app and your HTTP server.

Upvotes: 3

Related Questions