Problem with 'Access-Control-Allow-Origin' while developing Angular7 REST web app












0















i am developing webapp using angular7 and jersey2 frameworks.
Java backend runs on tomcat9 and angular on node.js.



I need to call http post method to send nickname and password to backend and get user as response.



angular code:



constructor( private http: HttpClient ) { }

private user : User = null;

private httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
}

login( nickname : String, password : String ) {
let data = {
"nickname": nickname,
"password": password
}
this.http.post<User>(
"localhost:8080/SRK/rest/users/auth",
JSON.stringify(data),
this.httpOptions
).subscribe((user : User) => { console.log(user); this.user = user; });


java rest code:



@Path(value = "users")
public class UserService {

@POST
@Path(value = "auth")
@Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public User auth(Map<String, String> nicknameAndPassword) {
String nickname = nicknameAndPassword.get("nickname");
String password = nicknameAndPassword.get("password");
return new UserController.getUserWithNicknameAndPassword(nickname, password);
}
}


I also tried to add "Access-Control-Allow-Origin": "*" to response header:



@POST
@Path(value = "auth")
@Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public Response getUserWithNicknameAndPassword(Map<String, String> nicknameAndPassword) {
String nickname = nicknameAndPassword.get("nickname");
String password = nicknameAndPassword.get("password");
return Response.ok()
.entity(new UserController.getUserWithNicknameAndPassword(nickname, password))
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
.build();
}


but i get this error in browser console when angular login method is called:



 OPTIONS http://localhost:8080/SRK/rest/users/auth 403

Access to XMLHttpRequest at 'http://localhost:8080/SRK/rest/users/auth'
from origin 'http://localhost:4200' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested resource.


My WEB-INF/web.xml contains this:



<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


I tried to install "access-control-allow-origin" chrome plugin and run angular app in chrome but the same error.



When i builded angular app to production and added to WebApp folder everything worked fine.
I really dont know where is the problem.
I appreciate every help.



SOLVED



I created proxy.config.json including this:



{
"/rest/*":{
"target": "http://localhost:8080/SRK",
"secure": false,
"changeOrigin": true
}
}


URI in anglar post method is now shorter:



this.http.post<User>(
/rest/users/auth",
JSON.stringify(data),
this.httpOptions
).subscribe((user : User) => { console.log(user); this.user = user; });


And I edited package.json:



"scripts": {
...
"start": "ng serve --proxy-config proxy.config.json",
...
},


Now i run angular app by command npm start instead of ng serve.



Thanks for your help.










share|improve this question





























    0















    i am developing webapp using angular7 and jersey2 frameworks.
    Java backend runs on tomcat9 and angular on node.js.



    I need to call http post method to send nickname and password to backend and get user as response.



    angular code:



    constructor( private http: HttpClient ) { }

    private user : User = null;

    private httpOptions = {
    headers: new HttpHeaders({
    'Content-Type': 'application/json'
    })
    }

    login( nickname : String, password : String ) {
    let data = {
    "nickname": nickname,
    "password": password
    }
    this.http.post<User>(
    "localhost:8080/SRK/rest/users/auth",
    JSON.stringify(data),
    this.httpOptions
    ).subscribe((user : User) => { console.log(user); this.user = user; });


    java rest code:



    @Path(value = "users")
    public class UserService {

    @POST
    @Path(value = "auth")
    @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
    @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
    public User auth(Map<String, String> nicknameAndPassword) {
    String nickname = nicknameAndPassword.get("nickname");
    String password = nicknameAndPassword.get("password");
    return new UserController.getUserWithNicknameAndPassword(nickname, password);
    }
    }


    I also tried to add "Access-Control-Allow-Origin": "*" to response header:



    @POST
    @Path(value = "auth")
    @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
    @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
    public Response getUserWithNicknameAndPassword(Map<String, String> nicknameAndPassword) {
    String nickname = nicknameAndPassword.get("nickname");
    String password = nicknameAndPassword.get("password");
    return Response.ok()
    .entity(new UserController.getUserWithNicknameAndPassword(nickname, password))
    .header("Access-Control-Allow-Origin", "*")
    .header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
    .header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
    .build();
    }


    but i get this error in browser console when angular login method is called:



     OPTIONS http://localhost:8080/SRK/rest/users/auth 403

    Access to XMLHttpRequest at 'http://localhost:8080/SRK/rest/users/auth'
    from origin 'http://localhost:4200' has been blocked by CORS policy:
    Response to preflight request doesn't pass access control check: No
    'Access-Control-Allow-Origin' header is present on the requested resource.


    My WEB-INF/web.xml contains this:



    <filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
    <init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value>
    </init-param>
    <init-param>
    <param-name>cors.allowed.methods</param-name>
    <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>CorsFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>


    I tried to install "access-control-allow-origin" chrome plugin and run angular app in chrome but the same error.



    When i builded angular app to production and added to WebApp folder everything worked fine.
    I really dont know where is the problem.
    I appreciate every help.



    SOLVED



    I created proxy.config.json including this:



    {
    "/rest/*":{
    "target": "http://localhost:8080/SRK",
    "secure": false,
    "changeOrigin": true
    }
    }


    URI in anglar post method is now shorter:



    this.http.post<User>(
    /rest/users/auth",
    JSON.stringify(data),
    this.httpOptions
    ).subscribe((user : User) => { console.log(user); this.user = user; });


    And I edited package.json:



    "scripts": {
    ...
    "start": "ng serve --proxy-config proxy.config.json",
    ...
    },


    Now i run angular app by command npm start instead of ng serve.



    Thanks for your help.










    share|improve this question



























      0












      0








      0








      i am developing webapp using angular7 and jersey2 frameworks.
      Java backend runs on tomcat9 and angular on node.js.



      I need to call http post method to send nickname and password to backend and get user as response.



      angular code:



      constructor( private http: HttpClient ) { }

      private user : User = null;

      private httpOptions = {
      headers: new HttpHeaders({
      'Content-Type': 'application/json'
      })
      }

      login( nickname : String, password : String ) {
      let data = {
      "nickname": nickname,
      "password": password
      }
      this.http.post<User>(
      "localhost:8080/SRK/rest/users/auth",
      JSON.stringify(data),
      this.httpOptions
      ).subscribe((user : User) => { console.log(user); this.user = user; });


      java rest code:



      @Path(value = "users")
      public class UserService {

      @POST
      @Path(value = "auth")
      @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
      @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
      public User auth(Map<String, String> nicknameAndPassword) {
      String nickname = nicknameAndPassword.get("nickname");
      String password = nicknameAndPassword.get("password");
      return new UserController.getUserWithNicknameAndPassword(nickname, password);
      }
      }


      I also tried to add "Access-Control-Allow-Origin": "*" to response header:



      @POST
      @Path(value = "auth")
      @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
      @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
      public Response getUserWithNicknameAndPassword(Map<String, String> nicknameAndPassword) {
      String nickname = nicknameAndPassword.get("nickname");
      String password = nicknameAndPassword.get("password");
      return Response.ok()
      .entity(new UserController.getUserWithNicknameAndPassword(nickname, password))
      .header("Access-Control-Allow-Origin", "*")
      .header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
      .header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
      .build();
      }


      but i get this error in browser console when angular login method is called:



       OPTIONS http://localhost:8080/SRK/rest/users/auth 403

      Access to XMLHttpRequest at 'http://localhost:8080/SRK/rest/users/auth'
      from origin 'http://localhost:4200' has been blocked by CORS policy:
      Response to preflight request doesn't pass access control check: No
      'Access-Control-Allow-Origin' header is present on the requested resource.


      My WEB-INF/web.xml contains this:



      <filter>
      <filter-name>CorsFilter</filter-name>
      <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
      <init-param>
      <param-name>cors.allowed.origins</param-name>
      <param-value>*</param-value>
      </init-param>
      <init-param>
      <param-name>cors.allowed.methods</param-name>
      <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
      </init-param>
      </filter>
      <filter-mapping>
      <filter-name>CorsFilter</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>


      I tried to install "access-control-allow-origin" chrome plugin and run angular app in chrome but the same error.



      When i builded angular app to production and added to WebApp folder everything worked fine.
      I really dont know where is the problem.
      I appreciate every help.



      SOLVED



      I created proxy.config.json including this:



      {
      "/rest/*":{
      "target": "http://localhost:8080/SRK",
      "secure": false,
      "changeOrigin": true
      }
      }


      URI in anglar post method is now shorter:



      this.http.post<User>(
      /rest/users/auth",
      JSON.stringify(data),
      this.httpOptions
      ).subscribe((user : User) => { console.log(user); this.user = user; });


      And I edited package.json:



      "scripts": {
      ...
      "start": "ng serve --proxy-config proxy.config.json",
      ...
      },


      Now i run angular app by command npm start instead of ng serve.



      Thanks for your help.










      share|improve this question
















      i am developing webapp using angular7 and jersey2 frameworks.
      Java backend runs on tomcat9 and angular on node.js.



      I need to call http post method to send nickname and password to backend and get user as response.



      angular code:



      constructor( private http: HttpClient ) { }

      private user : User = null;

      private httpOptions = {
      headers: new HttpHeaders({
      'Content-Type': 'application/json'
      })
      }

      login( nickname : String, password : String ) {
      let data = {
      "nickname": nickname,
      "password": password
      }
      this.http.post<User>(
      "localhost:8080/SRK/rest/users/auth",
      JSON.stringify(data),
      this.httpOptions
      ).subscribe((user : User) => { console.log(user); this.user = user; });


      java rest code:



      @Path(value = "users")
      public class UserService {

      @POST
      @Path(value = "auth")
      @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
      @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
      public User auth(Map<String, String> nicknameAndPassword) {
      String nickname = nicknameAndPassword.get("nickname");
      String password = nicknameAndPassword.get("password");
      return new UserController.getUserWithNicknameAndPassword(nickname, password);
      }
      }


      I also tried to add "Access-Control-Allow-Origin": "*" to response header:



      @POST
      @Path(value = "auth")
      @Consumes(MediaType.APPLICATION_JSON + ";charset=utf-8")
      @Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
      public Response getUserWithNicknameAndPassword(Map<String, String> nicknameAndPassword) {
      String nickname = nicknameAndPassword.get("nickname");
      String password = nicknameAndPassword.get("password");
      return Response.ok()
      .entity(new UserController.getUserWithNicknameAndPassword(nickname, password))
      .header("Access-Control-Allow-Origin", "*")
      .header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
      .header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
      .build();
      }


      but i get this error in browser console when angular login method is called:



       OPTIONS http://localhost:8080/SRK/rest/users/auth 403

      Access to XMLHttpRequest at 'http://localhost:8080/SRK/rest/users/auth'
      from origin 'http://localhost:4200' has been blocked by CORS policy:
      Response to preflight request doesn't pass access control check: No
      'Access-Control-Allow-Origin' header is present on the requested resource.


      My WEB-INF/web.xml contains this:



      <filter>
      <filter-name>CorsFilter</filter-name>
      <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
      <init-param>
      <param-name>cors.allowed.origins</param-name>
      <param-value>*</param-value>
      </init-param>
      <init-param>
      <param-name>cors.allowed.methods</param-name>
      <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
      </init-param>
      </filter>
      <filter-mapping>
      <filter-name>CorsFilter</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>


      I tried to install "access-control-allow-origin" chrome plugin and run angular app in chrome but the same error.



      When i builded angular app to production and added to WebApp folder everything worked fine.
      I really dont know where is the problem.
      I appreciate every help.



      SOLVED



      I created proxy.config.json including this:



      {
      "/rest/*":{
      "target": "http://localhost:8080/SRK",
      "secure": false,
      "changeOrigin": true
      }
      }


      URI in anglar post method is now shorter:



      this.http.post<User>(
      /rest/users/auth",
      JSON.stringify(data),
      this.httpOptions
      ).subscribe((user : User) => { console.log(user); this.user = user; });


      And I edited package.json:



      "scripts": {
      ...
      "start": "ng serve --proxy-config proxy.config.json",
      ...
      },


      Now i run angular app by command npm start instead of ng serve.



      Thanks for your help.







      java rest tomcat jersey-2.0 angular7






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 11:47







      Lukáš Slaninka

















      asked Jan 2 at 18:08









      Lukáš SlaninkaLukáš Slaninka

      103




      103
























          3 Answers
          3






          active

          oldest

          votes


















          0














          You can workaround it always sending the Access-Control-Allow-Origin header (How to handle CORS using JAX-RS with Jersey) or you can include a server like nginx to perform a reverse proxy for you eliminating the needs for the header



          Update:



          Sorry for late response, but here you find the nginx documentation: https://docs.nginx.com/?_ga=2.134190344.721047093.1546535765-158692192.1546535765



          Also, you need to change the nginx.conf to include something like this:



          location /<location_you_wish_for_your_proxy> {
          proxy_pass <your_back_endend_server_location_including_port_and_path>;
          proxy_http_version 1.1;
          proxy_set_header Host $host;
          }





          share|improve this answer


























          • I would like to try your second suggestion. Can you give me any tips how to proceed ?

            – Lukáš Slaninka
            Jan 2 at 19:52











          • I finally got it out using a proxy. Thanks for your help.

            – Lukáš Slaninka
            Jan 3 at 11:40



















          0














          In C# we do the following. Please check the java equivalent and write in your server side API code.
          In WebAPIConfig file add the namespace
          using System.Web.Http.Cors;



          Then add the following line of code in Register method:
          config.EnableCors(new EnableCorsAttribute("http://localhost:8080", headers: "", methods: ""));



          This will make the rest API to accept CORS calls.






          share|improve this answer































            0














            Your server should have something like Access-Control-Allow-Origin: * header in the response.






            share|improve this answer
























            • Thanks for helping me. I tried to add it to response header but unfortunately still the same error.

              – Lukáš Slaninka
              Jan 3 at 10:44











            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%2f54011133%2fproblem-with-access-control-allow-origin-while-developing-angular7-rest-web-ap%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can workaround it always sending the Access-Control-Allow-Origin header (How to handle CORS using JAX-RS with Jersey) or you can include a server like nginx to perform a reverse proxy for you eliminating the needs for the header



            Update:



            Sorry for late response, but here you find the nginx documentation: https://docs.nginx.com/?_ga=2.134190344.721047093.1546535765-158692192.1546535765



            Also, you need to change the nginx.conf to include something like this:



            location /<location_you_wish_for_your_proxy> {
            proxy_pass <your_back_endend_server_location_including_port_and_path>;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            }





            share|improve this answer


























            • I would like to try your second suggestion. Can you give me any tips how to proceed ?

              – Lukáš Slaninka
              Jan 2 at 19:52











            • I finally got it out using a proxy. Thanks for your help.

              – Lukáš Slaninka
              Jan 3 at 11:40
















            0














            You can workaround it always sending the Access-Control-Allow-Origin header (How to handle CORS using JAX-RS with Jersey) or you can include a server like nginx to perform a reverse proxy for you eliminating the needs for the header



            Update:



            Sorry for late response, but here you find the nginx documentation: https://docs.nginx.com/?_ga=2.134190344.721047093.1546535765-158692192.1546535765



            Also, you need to change the nginx.conf to include something like this:



            location /<location_you_wish_for_your_proxy> {
            proxy_pass <your_back_endend_server_location_including_port_and_path>;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            }





            share|improve this answer


























            • I would like to try your second suggestion. Can you give me any tips how to proceed ?

              – Lukáš Slaninka
              Jan 2 at 19:52











            • I finally got it out using a proxy. Thanks for your help.

              – Lukáš Slaninka
              Jan 3 at 11:40














            0












            0








            0







            You can workaround it always sending the Access-Control-Allow-Origin header (How to handle CORS using JAX-RS with Jersey) or you can include a server like nginx to perform a reverse proxy for you eliminating the needs for the header



            Update:



            Sorry for late response, but here you find the nginx documentation: https://docs.nginx.com/?_ga=2.134190344.721047093.1546535765-158692192.1546535765



            Also, you need to change the nginx.conf to include something like this:



            location /<location_you_wish_for_your_proxy> {
            proxy_pass <your_back_endend_server_location_including_port_and_path>;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            }





            share|improve this answer















            You can workaround it always sending the Access-Control-Allow-Origin header (How to handle CORS using JAX-RS with Jersey) or you can include a server like nginx to perform a reverse proxy for you eliminating the needs for the header



            Update:



            Sorry for late response, but here you find the nginx documentation: https://docs.nginx.com/?_ga=2.134190344.721047093.1546535765-158692192.1546535765



            Also, you need to change the nginx.conf to include something like this:



            location /<location_you_wish_for_your_proxy> {
            proxy_pass <your_back_endend_server_location_including_port_and_path>;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 3 at 17:18

























            answered Jan 2 at 19:06









            Pedro HPedro H

            3991521




            3991521













            • I would like to try your second suggestion. Can you give me any tips how to proceed ?

              – Lukáš Slaninka
              Jan 2 at 19:52











            • I finally got it out using a proxy. Thanks for your help.

              – Lukáš Slaninka
              Jan 3 at 11:40



















            • I would like to try your second suggestion. Can you give me any tips how to proceed ?

              – Lukáš Slaninka
              Jan 2 at 19:52











            • I finally got it out using a proxy. Thanks for your help.

              – Lukáš Slaninka
              Jan 3 at 11:40

















            I would like to try your second suggestion. Can you give me any tips how to proceed ?

            – Lukáš Slaninka
            Jan 2 at 19:52





            I would like to try your second suggestion. Can you give me any tips how to proceed ?

            – Lukáš Slaninka
            Jan 2 at 19:52













            I finally got it out using a proxy. Thanks for your help.

            – Lukáš Slaninka
            Jan 3 at 11:40





            I finally got it out using a proxy. Thanks for your help.

            – Lukáš Slaninka
            Jan 3 at 11:40













            0














            In C# we do the following. Please check the java equivalent and write in your server side API code.
            In WebAPIConfig file add the namespace
            using System.Web.Http.Cors;



            Then add the following line of code in Register method:
            config.EnableCors(new EnableCorsAttribute("http://localhost:8080", headers: "", methods: ""));



            This will make the rest API to accept CORS calls.






            share|improve this answer




























              0














              In C# we do the following. Please check the java equivalent and write in your server side API code.
              In WebAPIConfig file add the namespace
              using System.Web.Http.Cors;



              Then add the following line of code in Register method:
              config.EnableCors(new EnableCorsAttribute("http://localhost:8080", headers: "", methods: ""));



              This will make the rest API to accept CORS calls.






              share|improve this answer


























                0












                0








                0







                In C# we do the following. Please check the java equivalent and write in your server side API code.
                In WebAPIConfig file add the namespace
                using System.Web.Http.Cors;



                Then add the following line of code in Register method:
                config.EnableCors(new EnableCorsAttribute("http://localhost:8080", headers: "", methods: ""));



                This will make the rest API to accept CORS calls.






                share|improve this answer













                In C# we do the following. Please check the java equivalent and write in your server side API code.
                In WebAPIConfig file add the namespace
                using System.Web.Http.Cors;



                Then add the following line of code in Register method:
                config.EnableCors(new EnableCorsAttribute("http://localhost:8080", headers: "", methods: ""));



                This will make the rest API to accept CORS calls.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 2 at 18:25









                NiranNiran

                1




                1























                    0














                    Your server should have something like Access-Control-Allow-Origin: * header in the response.






                    share|improve this answer
























                    • Thanks for helping me. I tried to add it to response header but unfortunately still the same error.

                      – Lukáš Slaninka
                      Jan 3 at 10:44
















                    0














                    Your server should have something like Access-Control-Allow-Origin: * header in the response.






                    share|improve this answer
























                    • Thanks for helping me. I tried to add it to response header but unfortunately still the same error.

                      – Lukáš Slaninka
                      Jan 3 at 10:44














                    0












                    0








                    0







                    Your server should have something like Access-Control-Allow-Origin: * header in the response.






                    share|improve this answer













                    Your server should have something like Access-Control-Allow-Origin: * header in the response.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 2 at 18:32









                    Adam GenshaftAdam Genshaft

                    31829




                    31829













                    • Thanks for helping me. I tried to add it to response header but unfortunately still the same error.

                      – Lukáš Slaninka
                      Jan 3 at 10:44



















                    • Thanks for helping me. I tried to add it to response header but unfortunately still the same error.

                      – Lukáš Slaninka
                      Jan 3 at 10:44

















                    Thanks for helping me. I tried to add it to response header but unfortunately still the same error.

                    – Lukáš Slaninka
                    Jan 3 at 10:44





                    Thanks for helping me. I tried to add it to response header but unfortunately still the same error.

                    – Lukáš Slaninka
                    Jan 3 at 10:44


















                    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%2f54011133%2fproblem-with-access-control-allow-origin-while-developing-angular7-rest-web-ap%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

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas

                    Can't read property showImagePicker of undefined in react native iOS