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;








0















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:



Error on request



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.










share|improve this question






























    0















    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:



    Error on request



    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.










    share|improve this question


























      0












      0








      0








      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:



      Error on request



      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.










      share|improve this question
















      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:



      Error on request



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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 10:29









      Yosh Wong

      212




      212










      asked Mar 21 at 23:15









      DraykeDrayke

      152111




      152111






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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






          share|improve this answer























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



            );













            draft saved

            draft discarded


















            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









            0














            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






            share|improve this answer



























              0














              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






              share|improve this answer

























                0












                0








                0







                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






                share|improve this answer













                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







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 21 at 23:35









                manoj mallickmanoj mallick

                123




                123





























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    위키백과:대문 둘러보기 메뉴기부 안내모바일판 대문크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0CebuanoDeutschEnglishEspañolFrançaisItaliano日本語NederlandsPolskiPortuguêsРусскийSvenskaTiếng ViệtWinaray中文العربيةCatalàفارسیSrpskiУкраїнськаБългарскиНохчийнČeštinaDanskEsperantoEuskaraSuomiעבריתMagyarՀայերենBahasa IndonesiaҚазақшаBaso MinangkabauBahasa MelayuBân-lâm-gúNorskRomânăSrpskohrvatskiSlovenčinaTürkçe