Hello guys

I want to make a get request on an REST API . 
I am sending this get request:

return 
this.http.get('http://localhost:7990/bitbucket/rest/project/1.0/project/second',
 
{
"headers" : new HttpHeaders().append('Authorization', 'Basic 
YWRtaW46YWRtaW4=')
}).subscribe(data => {
console.log(data);
});

The REST resource i am calling looks like this:

@Produces({ MediaType.APPLICATION_JSON })
@Path("/second")
@CrossOrigin
public Response getFirstProjects() {
return Response.ok().header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Headers", "Authorization").build();
}
I am getting this error: "Response to preflight request doesn't pass access 
control check: No 'Access-Control-Allow-Origin' header is present on the 
requested resource. Origin 'http://localhost:4200' is therefore not allowed 
access. The response had HTTP status code 401."
I dont get why i get this error. I am new to Angular and REST in general. I 
dont know how to make this request. Can someone please give a 
explanation/correction or a full example of the client and server side of 
the request?

Info: The imports/constructor for the service where the request is in:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { HttpHeaders, HttpClient, HttpHandler } from '@angular/common/http';
import 'rxjs/add/operator/map';

constructor(public http:HttpClient, public httpHandler:HttpHandler) { 
console.log('Data service connected...');
}

The app.module.ts file: 
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { HttpHeaders, HttpClient, HttpHandler } from '@angular/common/http';
import { RouterModule, Routes } from '@angular/router'


import { AppComponent } from './app.component';
import { ProjectComponent } from './components/project/project.component';
import { ProjectService } from './services/project.service';
import { UserComponent } from './components/user/user.component';

@NgModule({
declarations: [
AppComponent,
ProjectComponent,
UserComponent
],
imports: [
BrowserModule,
FormsModule,
HttpClientModule
//HttpHeaders,
//HttpClient
],
providers: [ProjectService,
HttpClient
],
bootstrap: [AppComponent]
})
export class AppModule { }

Thanks for the help

-- 
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