I am making a angular POST call to a backend service. Usecase is such that request has no body, so I do like:
http.post("my/backend/service", null);
I observe that endpoint is not hit, and there is also no error.
Is this not the correct way of handling empty request body for POST?
post
method return an Observable
so you need either to subscribe
to the post
method or return the Observable
and subscribe
to your method. Calling the post
method and getting the Observable
is like preparing the request, subscribing to the Observable is like runing the query.
http.post("my/backend/service", null).subscribe();
You can find more about it in the last section of this Angular tutorial .
Because the service method returns an Observable of configuration data, the component subscribes to the method's return value.
The example use the get()
method, but the problem come from the type of the response: Observable
.
Send empty JSON object, May be it will work.
http.post("my/backend/service", {});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.