Access Control Allow Origin issue in Angular 2

前端 未结 5 832
心在旅途
心在旅途 2020-11-27 22:51

I have a problem with getting data from my node.js server.

The client side is:

    public getTestLines() : Observable {
    let hea         


        
5条回答
  •  孤独总比滥情好
    2020-11-27 23:17

    This has nothing to do with the client. Very simply you can solve this problem by adding Cors to the Configure method. like this:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                InitializeDatabase(app);
    
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
    
                app.UseMiddleware();
    
                app.UseSwagger();
    
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                });
    
                app.UseCors(s => s.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());  ==> This section
    
                app.UseMvc();
            }
    

    Now Restart your project and check again.

提交回复
热议问题