Api 来自 Ionic 应用程序的调用未命中服务器 Api
Api call from Ionic app not hitting on server Api
我是 Ionic 新手。我没有从这里得到任何解决方案。
这是我的ionic.config.json
{
"name":"BarcodeScannerApp",
"integrations": {
"cordova": {}
},
"type":"angular",
"proxies":[
{
"proxyUrl":"http://localhost:8085"
}
]
}
下面是服务中的方法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);
}
这给出了以下错误
POST http://192.168.0.9:8100/api/v1/barcode/scan 404 (Not Found)
服务器端方法如下
@RequestMapping(value = "api/v1/barcode/scan", method = {RequestMethod.POST})
public ResponseEntity<ServerResponse> getProductInfo(@RequestParam("barcodeInfo") String barcodeNo, @RequestParam("basketId") String basketId) {
return null;
}
我认为应该可以。您应该使用 HTTP header 等 "Content-type" 等
我解决了这个问题。这是 CORS 问题,我应该添加 @crossOrigin(" * ") 注释。
如果服务器启用了 CORS,它将解析 Access-Control-Request-* headers 并了解正在尝试从 http://localhost:8100(Ionic 客户端)使用自定义 Content-Type.
我是 Ionic 新手。我没有从这里得到任何解决方案。
这是我的ionic.config.json
{
"name":"BarcodeScannerApp",
"integrations": {
"cordova": {}
},
"type":"angular",
"proxies":[
{
"proxyUrl":"http://localhost:8085"
}
]
}
下面是服务中的方法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);
}
这给出了以下错误
POST http://192.168.0.9:8100/api/v1/barcode/scan 404 (Not Found)
服务器端方法如下
@RequestMapping(value = "api/v1/barcode/scan", method = {RequestMethod.POST})
public ResponseEntity<ServerResponse> getProductInfo(@RequestParam("barcodeInfo") String barcodeNo, @RequestParam("basketId") String basketId) {
return null;
}
我认为应该可以。您应该使用 HTTP header 等 "Content-type" 等
我解决了这个问题。这是 CORS 问题,我应该添加 @crossOrigin(" * ") 注释。 如果服务器启用了 CORS,它将解析 Access-Control-Request-* headers 并了解正在尝试从 http://localhost:8100(Ionic 客户端)使用自定义 Content-Type.