shyni
shyni

Reputation: 90

Api call from Ionic app not hitting on server Api

I am new to Ionic. I didn't get any solution for this from here.

This is my ionic.config.json

{
  "name":"BarcodeScannerApp",
  "integrations": {
    "cordova": {}
  },
  "type":"angular",
  "proxies":[
    {
      "proxyUrl":"http://localhost:8085"
    }
  ]
}

Below is the method in service class

public getProduct(barocode: any, basketBarcode: any): Observable<any> {
   this.url = '/api/v1/barcode/scan';
   let queryParameters = new HttpParams();
   queryParameters = queryParameters.set('barcodeInfo', barocode);
   queryParameters = queryParameters.set('basketId', basketBarcode);
   const requestOptions: any = {
     params: queryParameters
   };
   return this.httpclient.post(this.url, requestOptions);
 }

This gives below error

POST http://192.168.0.9:8100/api/v1/barcode/scan 404 (Not Found)

Server side method is below

   @RequestMapping(value = "api/v1/barcode/scan", method = {RequestMethod.POST})
public ResponseEntity<ServerResponse> getProductInfo(@RequestParam("barcodeInfo") String barcodeNo, @RequestParam("basketId") String basketId) {

    return null;
    }

Upvotes: 2

Views: 314

Answers (2)

shyni
shyni

Reputation: 90

I solved the issue . It was the CORS issue, which i was supposed to add @crossOrigin(" * ") annotation. If the server is CORS enabled, it will parse the Access-Control-Request-* headers and understand that a request is trying to be made from http://localhost:8100 (Ionic client) with a custom Content-Type.

Upvotes: 1

Hassan Ali
Hassan Ali

Reputation: 1029

I think it's should be work. You should use the HTTP header like "Content-type" etc

Upvotes: 0

Related Questions