I have an applicataion based on asp .net core boilerplate. I need to send http POST parameters from my Angular 6 app.
My service looks like this:
public findProduct(productCode: string) {
const url_ = 'api/product/findProduct';
const params = new URLSearchParams();
params.set('productCode', productCode);
return this.http.post(url_, params, httpHeaders)
.subscribe(
result => {
console.log(result);
},
error => {
console.log('There was an error: ')
}
);
I have imported URLSearchParams from @angular/http, but still I have the same problem. My POST URL is bad, because API expect POST URL like this: http://localhost:21021/api/product/findProduct?productCode=1111 and query string parameters like: productCode: 1111
but mine looks like this: http://localhost:21021/api/product/findProduct and setting request payload (always empty):
**{rawParams: "", queryEncoder: {}, paramsMap: {}}
paramsMap: {}
queryEncoder: {}
rawParams: ""**
My httpHeaders is: 'Content-Type': 'application/json', 'Accept': 'text/plain'
My question is how can I set expected API POST parameters in this service?
We have to pass params as 3rd parameter for post request
public findProduct(productCode: string) {
const url_ = 'api/product/findProduct';
const params = new URLSearchParams();
params.set('productCode', productCode);
return this.http.post(url_,,params, httpHeaders)
.subscribe(
result => {
console.log(result);
},
error => {
console.log('There was an error: ')
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With