How to send and get the result from Api in ionic 4

I am new in ionic 4, I want to send the barcode result to the api then get the api response result from the api. How to do it?

Is the result of the scan represented as JSON? What format is your endpoint expecting the data sent to it to be in? I have always had to set the content type when posting data. I imagine you will have to as well.

thank you for your reply, how to write the code? My code write like I show at above

Can you respond to the questions I asked?

Yeah, result of the scan represented as JSON.

Is the endpoint expecting json to be posted or form data?

post the result of the scan to API then get the response from API

‘Content-Type’: ‘multipart/form-data’,

You’ll want to create a header object and set its content type to application/json. You’ll more than likely need to stringify your json object. I always have to.

Are you using a .net api?

create at php or my service.ts?

sorry is form data not json

const myHeaders = new HttpHeaders().set(‘Content-Type’, ‘multipart/form-data’);
return await this.http.post(URL GOES HERE,’{}’,{headers: myHeaders})
.toPromise()
.then((data:any) => {

});

To learn about structuring the FormData object that will have to be passed to the API, here is a link: https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects

Perhaps this is caused by:

The Angular HttpClient is pretty smart about handling content type. If you feed it an ordinary object (i.e., you don’t manually stringify JSON), it will automatically declare a content type of application/json.

In this case, if you feed it a HttpParams, it will automatically declare the content type to be application/x-www-form-urlencoded;charset=UTF-8, which is hopefully what OP wants.

Thanks for weighing in. I was unaware of this.

ok, Thank you very much