0

I am trying to consume the following web-service

@POST
@Path("/delete")
@Produces(MediaType.APPLICATION_JSON)
public boolean deletePost(@QueryParam("idPost") String idPost) {
// logic here
}

However, trying to assign a value to the QueryParam idPost from angular does not work. Always idPost arrives with a value of null.

Try the 2 forms specified in the documentation but it does not work for me. What am I doing wrong?

public deletePost(idPost: number): Observable<any> {
    const options = idPost ?
    { params: new HttpParams().set('idPost', idPost.toString()) } : {};
    return this.httpClient.post('url-delete',options);
}

public deletePost(idPost: number): Observable<any> {
    const params = new HttpParams({fromString: 'idPost=' + idPost.toString()});
    return this.httpClient.post('url-delete',params);
}
6
  • 1
    In chrome dev tools do you see the param being sent out via the actual request? Commented Nov 18, 2019 at 15:59
  • yes, in request payload the idpost appears Commented Nov 18, 2019 at 16:17
  • I noticed that your path is /delete, but your post url is /url-delete. Is it possible that is the issue or is that just a placeholder? Commented Nov 18, 2019 at 16:18
  • I just put url-delete to not put the whole url Commented Nov 18, 2019 at 16:21
  • 2nd paramater in post is the body. are you sure you want to send the paramters in the body? Commented Nov 18, 2019 at 16:22

1 Answer 1

2

The 2nd Paramter in post is the body and the options should be a json like:

const options = { params: new HttpParams().set('name', 'xxx') }

Now invoke it like this:

public deletePost(idPost: number): Observable<any> {
    const options = {params: new HttpParams({fromString: 'idPost=' + idPost.toString()})};
    return this.httpClient.post('url-delete',{}, options); // empty body
}
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.