1

I could send a body(json) in Postman for a GET request.

enter image description here

My Problem is I am not able to do the same in my yes-no.service.ts file.

getYesNoDropdowns() {
  return this.http.get(AppComponent.lookUpListUrl, { headers: headers });
}

How do I achieve this? I have to use only Get.

Thanks in advance!

Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62
iamP
  • 307
  • 1
  • 3
  • 13

1 Answers1

0

Posts have a body, gets do not. You will need to put the data on the query string if you are using a get.

Adrian Brand
  • 20,384
  • 4
  • 39
  • 60
  • 1
    Thanks @adrian-brand, I am aware that posts have body as per the API I want to get data from, it has to be a get request and I have to send the data in the body like I did in postman which is working fine. I could not pass the body into the HTTP get() method. Can you please show syntactically what you meant by sending a query string? – iamP Jul 27 '20 at 03:22
  • `?data=${encodeURIComponent(JSON.stringify(yourBodyObject))}` and you can use decodeURIComponent on the server – Adrian Brand Jul 27 '20 at 04:35
  • I am not allowed to modify anything on the server, I can only make API requests. How is it that I am able to do it using Postman? – iamP Jul 27 '20 at 05:23
  • 1
    Postman allows you to construct any request you want, the Angular http service follows the standard. – Adrian Brand Jul 27 '20 at 05:50
  • 4
    Then above isn't answering the question or providing a solution, Why is this marked as correct answer – Alex Pappas Sep 22 '21 at 11:26