0

I have the below code for which i use to consume data through a REST API using http.post() method in angular 5.

return this._http.post(this.basePath,null, {
      headers: this.myHeaders,
      params: {
        transaction_id : "22"
      } ,
      observe: 'response',
      responseType: 'json'
    })
      .catch(this._errorHandler);

i can successfully fetch the data using the http.get() , but i get a 500 (Internal Server Error) when using post.

What might i be missing?

2 Answers 2

1

What does the backend service expect when you make an HTTP POST? Currently you're sending an empty body, which is most probably the cause of the HTTP 500 (Internal Server Error).

Just because you can make an HTTP GET request, doesn't always mean you can make an HTTP POST request to the same URL. POSTs often expect a body of some description. If a POST isn't supported you would expect the backend serice to return an HTTP 406 (Method Not Supported), but that depends on how well the backend service is written.

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

2 Comments

it only expects the "transaction_id" parameter for which i have passed
You're passing that as a query param, does it need to be in the body? what encoding / mime type is the server expecting - form or json?
0

I just had to pass the parameters as part of the body options on the post method as per below.

let bodyParams = {transaction_id : "22"};

return this._http.post(this.basePath,bodyParams , {
          headers: this.myHeaders,,
          observe: 'response',
          responseType: 'json'
        })
          .catch(this._errorHandler);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.