0

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
  • 5,868
  • 12
  • 32
  • 54
iamP
  • 197
  • 2
  • 11

1 Answers1

2

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
  • 17,318
  • 4
  • 30
  • 54
  • 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
  • 2
    Then above isn't answering the question or providing a solution, Why is this marked as correct answer – Cold Cerberus Sep 22 '21 at 11:26