@angular.
I want to access different devices web server depending on user input(user specify the ip address) depending on that ip address provided by user i create the http request - for example if user provide ip address as 10.234.1.2 then my request is http://10.234.1.2/api/get/elm?=STATE(request changes depend on ip). if i set proxy in JOSN file with remote = “http://10.234.1.2” then it works fine.i getting response. but i want to dynamically handle ip address.
Request code -
Header - >
headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa("admin:Abcd1234@") ,
'Access-Control-Allow-Origin': "*"
});
Request ->
return this._http.get<IEmployee[]>("http://10.232.5.213/api/get/data?elm=STATE",{headers: this.headers})
.pipe(
catchError(err => {
console.log('Handling error locally and rethrowing it...', err);
return throwError(err);
})
);
How to set that ip address to config.json dynamically depends on user input or any other solution
For running in java script i set corporate proxy using -
let request = require('request');
var proxiedRequest = request.defaults({'proxy': proxyUrl});
if i try to set it in proxy.config.json
{
"/api" : {
"target" : "http://proxy.company.com:8080",
"secure" : false,
"changeOrigin": true
}
}
First problem - - I get CORS issue. Access to XMLHttpRequest at
… has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
Second problem - if i set header to request then Request is send as OPTION protocol not get request and server reject the request with “Not Implemented”