0
I’m sending a request for a project that has the structure:
- Frontend: Angular
- Backend: ASP.NET Core
When sending this request, my controller returns the following message:
System.Net.Http.Httprequestexception: Failed to proxy the request to http: //api / product / Insert, because the request to the proxy target failed. Check that the proxy target server is running and Accepting requests to http: //localhost: 50005 /.
Looking for any resolution I saw on the microsoft site the inclusion in startup.Cs of a sp.UseProxy.. then tried with only one, but none solved my problem.
spa.UseProxyToSpaDevelopmentServer ("http//localhost:50005/");
and
spa.UseProxyToSpaDevelopmentServer ("http: // localhost:4200/");
Angular code:
import { Inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Product } from './product';
const headers: HttpHeaders = new HttpHeaders();
headers.set('Content-Type', 'application/x-www-form-urlencoded');
@Injectable({
providedIn: 'root'
})
export class ProductService {
url: string;
http: any;
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
this.http = http;
this.url = baseUrl;
}
insertProd(product: Product): Observable<Product>{
return this.http.post(this.url + '/api/product/insert', product, headers);
}
}