0
내 Angular 4 애플리케이션에서 asp.net 웹 API 인 서버에 대한 호출을 만들려고합니다. 내가 허용되지 않는 방법을 얻고 호출하려고 할 때 내 서버와 지금, 작업 보인다메서드가 허용되지 않습니다 405 애트리뷰트 httpclient에서 asp.net 웹 API로 호출하려고 시도 할 때
WebApi.config :
public static void Register(HttpConfiguration config)
{
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
컨트롤러 방법 예 :
[HttpGet, Route("api/authentication")]
public IHttpActionResult Get(string username, string password)
{
var s = new ApartmentService();
if (!s.CheckIfValidLogin(username, password))
{
return NotFound();
}
return Ok();
}
클라이언트 코드 :
public url = 'http://localhost:50743/api/authentication';
login(username: string, password: string): Observable<any> {
let params = new HttpParams();
params.append('username', username);
params.append('password', password);
return this.http.get(this.url, {
params: params,
headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'),
}).map((result: Response) => result.json());
}
또한 헤더 내용 유형도 시도했습니다. application/json 또한 작동하지 않았습니다.
오류 : 나는 우체부와 요청 ...
는 잘 작동합니다.
을 참조하십시오 ', this.http.get (this.url를 반환 ...'- (가)'http' 거기에서, 그것은'HttpClientModule' 또는'HttpModule'입니까? –