Http failure response for localhost api request: 0 Unknown Error - AngularHow to use java.net.URLConnection to fire and handle HTTP requestsHow to make CORS-enabled HTTP requests in Angular 2?angular2 http post request get a errorrest API call (from angular) in webpack server returns 401Spring Boot, Angular 2, CORS “Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.”How to add CORS request in header in Angular 5Http failure response for (unknown url): 0 Unknown Error - Only on Angular 5cors enable in Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight responseWith Angular 7 use HTTP API for POST and command error headers missingRequest header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response(Jenkins API)
High voltage LED indicator 40-1000 VDC without additional power supply
Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?
Fully-Firstable Anagram Sets
How is it possible to have an ability score that is less than 3?
Why is Minecraft giving an OpenGL error?
How to plot on a curved plane?
Perform and show arithmetic with LuaLaTeX
Why are electrically insulating heatsinks so rare? Is it just cost?
Compress a signal by storing signal diff instead of actual samples - is there such a thing?
How can bays and straits be determined in a procedurally generated map?
Can I make popcorn with any corn?
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
How can I make my BBEG immortal short of making them a Lich or Vampire?
RSA: Danger of using p to create q
Why doesn't H₄O²⁺ exist?
Dynamic programming approach for finding perfect square subsequence
What are these boxed doors outside store fronts in New York?
When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?
Paid for article while in US on F-1 visa?
Have astronauts in space suits ever taken selfies? If so, how?
I'm planning on buying a laser printer but concerned about the life cycle of toner in the machine
Pattern match does not work in bash script
What does it mean to describe someone as a butt steak?
What does the "remote control" for a QF-4 look like?
Http failure response for localhost api request: 0 Unknown Error - Angular
How to use java.net.URLConnection to fire and handle HTTP requestsHow to make CORS-enabled HTTP requests in Angular 2?angular2 http post request get a errorrest API call (from angular) in webpack server returns 401Spring Boot, Angular 2, CORS “Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.”How to add CORS request in header in Angular 5Http failure response for (unknown url): 0 Unknown Error - Only on Angular 5cors enable in Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight responseWith Angular 7 use HTTP API for POST and command error headers missingRequest header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response(Jenkins API)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to create a communication to my Java Jetty Backend from my Angular application. When I try to execute my request I receive the following error:

My code on client side: (Angular 7.2.1). I'm also using a HttpInterceptor for authentication that should work. I'm also running the code in development mode with ng serve.
@Injectable(
providedIn: 'root'
)
export class NgHydrantService
constructor(private http: HttpClient)
public register(entity: IEntityDescription): Observable<StandardResponsePacket>
let packet = new RegisterEntityRequestPacket(entity);
return this.http.post(this._apiUrl, packet.toJson())
.pipe(
map(value =>
console.log('register result:', value); //<-- never executed
return <StandardResponsePacket>HydrantPackage.fromJson(value)
)
);
//The interceptor
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>
// add authorization header with basic auth credentials if available
if (this.user != null)
const clonedRequest = request.clone(
headers: request.headers.set('Authorization', `Basic $this.user.getAuth()`)
.set('Accept','application/json')
);
//This debug line works and looks good!
console.log('NgHydrantAuthInterceptor#intercept', clonedRequest);
return next.handle(clonedRequest);
return next.handle(request);
My Code on server side: (Jetty-9.4.14.v20181114) that runs on localhost.
public final class PacketHandler extends AbstractHandler
@Override
public void handle( String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response ) throws IOException
try
// Declare response encoding and types
response.setContentType( "application/json; charset=utf-8" );
// Enable CORS
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, HEAD");
response.addHeader("Access-Control-Allow-Headers", "X-PINGOTHER, Origin, X-Requested-With, Content-Type, Accept");
response.addHeader("Access-Control-Max-Age", "1728000");
//... more stuff
finally
// Inform jetty that this request was handled
baseRequest.setHandled( true );
Things I checked:
- During research some people reference problems with CORS (that's why I added the header entries in the server side code)
- The same request in Postman works without any problems
- There are no logs on the server side
My question is about a possible solution to get responses from my server during development.
java
add a comment |
I'm trying to create a communication to my Java Jetty Backend from my Angular application. When I try to execute my request I receive the following error:

My code on client side: (Angular 7.2.1). I'm also using a HttpInterceptor for authentication that should work. I'm also running the code in development mode with ng serve.
@Injectable(
providedIn: 'root'
)
export class NgHydrantService
constructor(private http: HttpClient)
public register(entity: IEntityDescription): Observable<StandardResponsePacket>
let packet = new RegisterEntityRequestPacket(entity);
return this.http.post(this._apiUrl, packet.toJson())
.pipe(
map(value =>
console.log('register result:', value); //<-- never executed
return <StandardResponsePacket>HydrantPackage.fromJson(value)
)
);
//The interceptor
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>
// add authorization header with basic auth credentials if available
if (this.user != null)
const clonedRequest = request.clone(
headers: request.headers.set('Authorization', `Basic $this.user.getAuth()`)
.set('Accept','application/json')
);
//This debug line works and looks good!
console.log('NgHydrantAuthInterceptor#intercept', clonedRequest);
return next.handle(clonedRequest);
return next.handle(request);
My Code on server side: (Jetty-9.4.14.v20181114) that runs on localhost.
public final class PacketHandler extends AbstractHandler
@Override
public void handle( String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response ) throws IOException
try
// Declare response encoding and types
response.setContentType( "application/json; charset=utf-8" );
// Enable CORS
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, HEAD");
response.addHeader("Access-Control-Allow-Headers", "X-PINGOTHER, Origin, X-Requested-With, Content-Type, Accept");
response.addHeader("Access-Control-Max-Age", "1728000");
//... more stuff
finally
// Inform jetty that this request was handled
baseRequest.setHandled( true );
Things I checked:
- During research some people reference problems with CORS (that's why I added the header entries in the server side code)
- The same request in Postman works without any problems
- There are no logs on the server side
My question is about a possible solution to get responses from my server during development.
java
add a comment |
I'm trying to create a communication to my Java Jetty Backend from my Angular application. When I try to execute my request I receive the following error:

My code on client side: (Angular 7.2.1). I'm also using a HttpInterceptor for authentication that should work. I'm also running the code in development mode with ng serve.
@Injectable(
providedIn: 'root'
)
export class NgHydrantService
constructor(private http: HttpClient)
public register(entity: IEntityDescription): Observable<StandardResponsePacket>
let packet = new RegisterEntityRequestPacket(entity);
return this.http.post(this._apiUrl, packet.toJson())
.pipe(
map(value =>
console.log('register result:', value); //<-- never executed
return <StandardResponsePacket>HydrantPackage.fromJson(value)
)
);
//The interceptor
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>
// add authorization header with basic auth credentials if available
if (this.user != null)
const clonedRequest = request.clone(
headers: request.headers.set('Authorization', `Basic $this.user.getAuth()`)
.set('Accept','application/json')
);
//This debug line works and looks good!
console.log('NgHydrantAuthInterceptor#intercept', clonedRequest);
return next.handle(clonedRequest);
return next.handle(request);
My Code on server side: (Jetty-9.4.14.v20181114) that runs on localhost.
public final class PacketHandler extends AbstractHandler
@Override
public void handle( String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response ) throws IOException
try
// Declare response encoding and types
response.setContentType( "application/json; charset=utf-8" );
// Enable CORS
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, HEAD");
response.addHeader("Access-Control-Allow-Headers", "X-PINGOTHER, Origin, X-Requested-With, Content-Type, Accept");
response.addHeader("Access-Control-Max-Age", "1728000");
//... more stuff
finally
// Inform jetty that this request was handled
baseRequest.setHandled( true );
Things I checked:
- During research some people reference problems with CORS (that's why I added the header entries in the server side code)
- The same request in Postman works without any problems
- There are no logs on the server side
My question is about a possible solution to get responses from my server during development.
java
I'm trying to create a communication to my Java Jetty Backend from my Angular application. When I try to execute my request I receive the following error:

My code on client side: (Angular 7.2.1). I'm also using a HttpInterceptor for authentication that should work. I'm also running the code in development mode with ng serve.
@Injectable(
providedIn: 'root'
)
export class NgHydrantService
constructor(private http: HttpClient)
public register(entity: IEntityDescription): Observable<StandardResponsePacket>
let packet = new RegisterEntityRequestPacket(entity);
return this.http.post(this._apiUrl, packet.toJson())
.pipe(
map(value =>
console.log('register result:', value); //<-- never executed
return <StandardResponsePacket>HydrantPackage.fromJson(value)
)
);
//The interceptor
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>
// add authorization header with basic auth credentials if available
if (this.user != null)
const clonedRequest = request.clone(
headers: request.headers.set('Authorization', `Basic $this.user.getAuth()`)
.set('Accept','application/json')
);
//This debug line works and looks good!
console.log('NgHydrantAuthInterceptor#intercept', clonedRequest);
return next.handle(clonedRequest);
return next.handle(request);
My Code on server side: (Jetty-9.4.14.v20181114) that runs on localhost.
public final class PacketHandler extends AbstractHandler
@Override
public void handle( String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response ) throws IOException
try
// Declare response encoding and types
response.setContentType( "application/json; charset=utf-8" );
// Enable CORS
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, HEAD");
response.addHeader("Access-Control-Allow-Headers", "X-PINGOTHER, Origin, X-Requested-With, Content-Type, Accept");
response.addHeader("Access-Control-Max-Age", "1728000");
//... more stuff
finally
// Inform jetty that this request was handled
baseRequest.setHandled( true );
Things I checked:
- During research some people reference problems with CORS (that's why I added the header entries in the server side code)
- The same request in Postman works without any problems
- There are no logs on the server side
My question is about a possible solution to get responses from my server during development.
@Injectable(
providedIn: 'root'
)
export class NgHydrantService
constructor(private http: HttpClient)
public register(entity: IEntityDescription): Observable<StandardResponsePacket>
let packet = new RegisterEntityRequestPacket(entity);
return this.http.post(this._apiUrl, packet.toJson())
.pipe(
map(value =>
console.log('register result:', value); //<-- never executed
return <StandardResponsePacket>HydrantPackage.fromJson(value)
)
);
//The interceptor
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>
// add authorization header with basic auth credentials if available
if (this.user != null)
const clonedRequest = request.clone(
headers: request.headers.set('Authorization', `Basic $this.user.getAuth()`)
.set('Accept','application/json')
);
//This debug line works and looks good!
console.log('NgHydrantAuthInterceptor#intercept', clonedRequest);
return next.handle(clonedRequest);
return next.handle(request);
@Injectable(
providedIn: 'root'
)
export class NgHydrantService
constructor(private http: HttpClient)
public register(entity: IEntityDescription): Observable<StandardResponsePacket>
let packet = new RegisterEntityRequestPacket(entity);
return this.http.post(this._apiUrl, packet.toJson())
.pipe(
map(value =>
console.log('register result:', value); //<-- never executed
return <StandardResponsePacket>HydrantPackage.fromJson(value)
)
);
//The interceptor
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>
// add authorization header with basic auth credentials if available
if (this.user != null)
const clonedRequest = request.clone(
headers: request.headers.set('Authorization', `Basic $this.user.getAuth()`)
.set('Accept','application/json')
);
//This debug line works and looks good!
console.log('NgHydrantAuthInterceptor#intercept', clonedRequest);
return next.handle(clonedRequest);
return next.handle(request);
java
java
edited Mar 22 at 10:29
Yosh Wong
212
212
asked Mar 21 at 23:15
DraykeDrayke
152111
152111
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Can you please follow the steps in below link
https://www.html5rocks.com/en/tutorials/cors/
For quick solution add below plugin in your chrome
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290608%2fhttp-failure-response-for-localhost-api-request-0-unknown-error-angular%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Can you please follow the steps in below link
https://www.html5rocks.com/en/tutorials/cors/
For quick solution add below plugin in your chrome
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
add a comment |
Can you please follow the steps in below link
https://www.html5rocks.com/en/tutorials/cors/
For quick solution add below plugin in your chrome
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
add a comment |
Can you please follow the steps in below link
https://www.html5rocks.com/en/tutorials/cors/
For quick solution add below plugin in your chrome
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
Can you please follow the steps in below link
https://www.html5rocks.com/en/tutorials/cors/
For quick solution add below plugin in your chrome
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
answered Mar 21 at 23:35
manoj mallickmanoj mallick
123
123
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290608%2fhttp-failure-response-for-localhost-api-request-0-unknown-error-angular%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown