나는 우리 회사 직원들이 아우렐 리아를 사용하여 즉석에서 판매하려는 제품이나 서비스에 대한 광고를 올릴 수있는 작은 포럼을 만들고 있습니다. 나는 잘 작동하는 광고 페이지 목록을 가지고 있는데, 각각의 광고에 대한 세부 정보 페이지는 api에서 요청을 얻음으로써 잘 작동한다. 그러나 누군가가 광고에 코멘트를 추가하려고 할 때 나는 포스트 reqeust 일을 얻는 것처럼 보일 수 없다.http-fetch-client가 옵션 요청을 작성하는 Post
@inject(HttpClient)
export class ApiData {
constructor(httpClient) {
httpClient.configure(config => {
config
.withBaseUrl("MyUrl");
});
this.http = httpClient;
//.configure(x => {x.withHeader('Content-Type', 'application/json');});
}
postAdvertComment(comment, id) {
return this.http.fetch(`/adverts/${id}/comments`, {
method: "post",
body: json(comment),
headers: {
'Accept': 'application/json'
}
});
}
getAdverts() {
return this.http.fetch("/adverts")
.then(response => {
return this.adverts = response.json();
});
}
getAdvert(id) {
return this.http.fetch(`/adverts/${id}`)
.then(response => {
return this.advert = response.json();
});
}
}
우리가 CORS 몇 가지 문제를 가지고 한이 프로젝트, 모두 내가 시도하고 게시물을 실행하지만 때 등 모든 방법
<add key="CorsAllowedOrigins" value="*" />
<add key="CorsAllowedHeaders" value="" />
<add key="CorsAllowedMethods" value="*" />
을 포함하여 API의 AllowCors 태그에 추가하여 해결을하는 , 옵션 메소드를 실행하고 400 Bad 요청을 리턴합니다. Here
우리는 또한 다음과 같은 CORS 오류 얻을 : 그것은 우리의 C#을 API를 사용하거나 내가 아우렐 리아에서 게시하기 위해 노력하고있어 방법에 문제가 있는지 모르겠어요
Fetch API cannot load MyURL/api/adverts/2/comments. Response to preflight
request doesn't pass access control check: No 'Access-Control-Allow-Origin'
header is present on the requested resource. Origin 'http://localhost:49877' is
therefore not allowed access. The response had HTTP status code 400. If an
opaque response serves your needs, set the request's mode to 'no-cors' to fetch
the resource with CORS disabled.
을하지만, 우리는 시도 우편 배달부에서 요청을 보내고 잘 작동, jquery를 사용하여 동일한 응용 프로그램 내에서 게시물 요청을 보내려고하고 괜찮 작동하고 모든 요청을 잘 작동하지만, 어떤 이유로이 게시물은 모든 종류의 문제가 발생합니다.