Hi Team,

*In my Angular 7 Program:*

*I am trying to access another website URL or some API's of other website 
URL through my Angular 7.*

*I am also trying to access RESTFul Web Services from other Server through 
Angular.*

*I installed  "Allow-Control-Allow-Origin: "  on my Chrome Browser to 
enable CQRS.*

*I have written a TypeScript Program:*

private _apiUrl = 'api/data/removed remaining content';

constructor(private _http: HttpClient) { }

FunctionY() {
let headers = new HttpHeaders();
headers.append('Content-Type','application/json');
headers.append('Accept', 'application/json');
headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, 
PATCH, PUT');
headers.append('Access-Control-Allow-Origin', 'http://Removed URL.org');
headers.append('Access-Control-Allow-Headers', "X-Requested-With, 
Content-Type, Origin, Authorization, Accept, Client-Security-Token, 
Accept-Encoding");
headers.append('Access-Control-Allow-Credentials', 'false');
let options = { headers: headers };
console.log("options", options);

return this._http.get(this._apiUrl,options).pipe(map(result => result));

 
*Created a file: proxy.conf.json*

{
"/api": {
"target": "http://removed URL.org",
"secure": false,
"pathRewrite": {
"^/api": ""
},
"changeOrigin": true
}
}


*Package.json*

"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},


*I ran the program using *ng serve* and  also using *npm start

*I am able to get the RestFul WebServices from other Server after disabling 
CQRS on my Chrome Browser.*
*But, I am not able to get the response of another website url or API url 
after disabling CQRS on my Chrome Browser.*

*-------------------------------------------------------------------------------------------------------------*
*I am getting an exception as: *

*Access to XMLHttpRequest at 'URL Removed here' (redirected from 
'http://localhost:4200/api/data/') from origin 'http://localhost:4200' has 
been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is 
present on the requested resource.*

*Error HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: 
"Unknown Error", url: null, ok: false, …}*

*Cross-Origin Read Blocking (CORB) blocked cross-origin response 
https://samples.openweathermap.org/data/2.5/history/city?q=Warren,OH&appid=b6907d289e10d714a6e88b30761fae22/data/2.5/history/city?q=Warren,OH&appid=b6907d289e10d714a6e88b30761fae22
 
with MIME type application/json. See 
https://www.chromestatus.com/feature/5629709824032768 for more details.*
*---------------------------------------------*

*Can you please let me know how can I get response from both Restful 
Webservices and other Websites or API URLs after disabling CQRS on my 
Chrome? What needs to be done.?*

*Thanks *
*Suresh*


-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to