While developing an angular application with a restful API get(), I encountered a few errors such as unauthorization error:401 which I managed to resolve. However, now I am facing another error that seems quite straightforward. I even tried adding the CORS package but to no avail.
I have been tirelessly searching for solutions but so far, my efforts have been in vain. I even went back and revised my previous question but received no response.
my-httpservice.service
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { Http, Response, Headers, RequestOptions, URLSearchParams } from
'@angular/http';
@Injectable()
export class MyHttpserviceService {
constructor(private http:Http) {}
server_grid_Get(){
var request = new XMLHttpRequest();
var user = "Root";
var pass = "root";
//Use Basic authentication
request.setRequestHeader("Authorization", "Basic " + btoa(user + ":" + pass));
request.setRequestHeader('Content-Type','application/json');
request.setRequestHeader('Access-Control-Allow-Credential','true');
request.open("GET", "http://192.100.00.000:0000/_db/xxxxx_app/_api/document/wsdl_test/4934434",true);
return this.http.get("http://192.100.00.000:0000/_db/xxxx_app/_api/document/wsdl_test/4934434").map(response => response.json());
request.addEventListener('load', function(event) {
if (request.status >= 200 && request.status < 300) {
console.log(request.responseText);
} else {
console.warn(request.statusText, request.responseText);
}
});
request.send();
}
}