0

I am running an Angular 4.x app and have a GET request to an endpoint that has querystring parameters such as the following :

https://dev.mywebsite.com/debug/me/user?__token=1000001445.k4mv42stmo1h7x1&apiversion=1&appid=3apiversion=1&appid=3

This works when I add this into postman and I can get a response back however when I run the following code in my Angular component it fails and gives the following error(s)

constructor(private http: HttpClient) { }

ngOnInit(): void {
    this.http.get('https://dev.website.com/debug/me/user', {
        params: { token:'1000001445.k4mv42stmo1h7x1', appid:3 }
    })
        .subscribe(data => {
        console.log('data', data);
    });
}

In the console.log in the network tab I can see this request has [object Object] under the the Headers tab in the Querystring section - why is this?

3
  • Not quite familiar with Angular 4 myself but don't you need to set params using HttpParams class (angular.io/api/common/http/HttpParams)? Commented Jan 24, 2018 at 14:19
  • you should call the get by passing in https://dev.mywebsite.com/debug/me/user?__token=1000001445.k4mv42stmo1h7x1&apiversion=1&appid=3apiversion=1&appid=3. without params. Commented Jan 24, 2018 at 14:39
  • From the docs, params can be of type HttpParams | {[param: string]: string | string[];}; so what you have is valid except the values should be strings appid: '3'. This will generate a url of https://dev.website.com/debug/me/user?token=1000001445.k4mv42stmo1h7x1&appId=3. From the url you posted, it looks like you are missing some fields from your params object Commented Jan 24, 2018 at 17:59

1 Answer 1

1

Try this:

    import { HttpClient, HttpParams } from "@angular/common/http";

    this.http.get('https://dev.website.com/debug/me/user',
       { params: new HttpParams()
    .set('token', '1000001445.k4mv42stmo1h7x1')
    .set('appid', '3') }).subscribe....

If need be, do some logging on your back end to ensure it is receiving the correct parameters and returning the right data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.