0

This is my code segment for fetching data from REST using angular HTTP, I can not pass any body inside the request.

this.http.get('paymentadvicelist').map((res: Response) => {
    return res.json();
})
3
  • If you are using GET method for call then you can pass your data using query params in URL and if you want to pass data as body then change your method type to POST Commented Feb 1, 2018 at 9:48
  • Is there any other way to achieve this by using GET method only?. Commented Feb 1, 2018 at 9:50
  • No . GET method in webservices do not accept body. But talking about alternative way then you can pass data in headers of GET webservice. Commented Feb 1, 2018 at 10:03

1 Answer 1

1

It depends on what type your "http" member is.

If you use the (newer) HttpClient API then you can use the httpClient.request() method (like httpClient.request("GET", url, {body: theRequestBody}).

If you use the older Http class (which is deprecated since angular 4.3) then you can set the request body in the request options, see the API documentation here.

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.