0

Im trying to use URLSearchParams to fill in querystring parameters and their values. However, the resulting url that seems to get used on the http call doesnt look like its including any of the querystring info. What am I doing wrong? Im looking at the network tab on the chrome dev tools

getBlogPost(postId:string): Observable<BlogPost> {
     var myHeaders = new Headers();
     myHeaders.append('Content-Type', 'application/json');        
     let myParams = new URLSearchParams();
     myParams.append('Id', postId);
     let options = new RequestOptions({ headers: myHeaders, params: myParams });                  
     return this.http.get("http://myapi.testapp.com/api/gfNet/GetBlogPost",options)
         .map((res: Response) => res.json())
         .catch(this.handleError);
 }

[ update ]
duh... this one of my import statements. Notice Im missing something
that something is URLSearchParams
Once I added that with the others from the http module, things started working and the url querystring showed up

import { Http, Response, Headers, RequestOptions} from '@angular/http';
Gajanan Kulkarni
  • 697
  • 6
  • 22
bitshift
  • 6,026
  • 11
  • 44
  • 108
  • Possible duplicate of [How to pass url arguments (query string) to a HTTP request on Angular 2](https://stackoverflow.com/questions/34475523/how-to-pass-url-arguments-query-string-to-a-http-request-on-angular-2) – Rachid O Oct 02 '17 at 21:22
  • Possible duplicate of [Error when unit testing: "Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1"](https://stackoverflow.com/questions/43612837/error-when-unit-testing-uncaught-in-promise-syntaxerror-unexpected-token-o) – Estus Flask Oct 02 '17 at 22:03

0 Answers0