2017-05-11 1 views
0

제어 : 내 요청에 노 cache` 필드를 RSS 피드를 요청할 때캐시 제어 자바 스크립트 요청

나는 그것을 거부 난 콘텐츠 형의 경우 에 넣어해야하는지 값 종료 그림이 잘 작동 캔트하지만, Cachce-제어 올바르게 추가

코드 :

options = {uri :SUPPORT_FEED_URI, 
      headers : { 
         'Content-Type': 'application/x-www-form-urlencoded', 
         'Cache-Control': 'no-cache' 
         }, 
      } 

request.get(options) 
       .on('error', (err) => { reject(err); }) 
       .pipe(feedparser) 
       .on('end',() => { return resolve(items); }); 

내가 요청 헤더에 무엇을 얻을 :

Accept:*/* 
Accept-Encoding:gzip, deflate, sdch 
Accept-Language:en-US,en;q=0.8 
Access-Control-Request-Headers:cache-control <-- doesnt seems to be right Want something like Cache-Control : no-cache 
Access-Control-Request-Method:GET 
Connection:keep-alive 
Host: xxxx.yyyy.zz 
Origin:http://127.0.0.1:8888 
Referer:http://127.0.0.1:8888/webconsole/ 
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 
content-type:application/x-www-form-urlencoded 
,536,

답변

1

URL이 다른 도메인에 있거나 다른 출처로 간주되므로 캡처가 CORS 비행 전 (OPTIONS) 요청입니다.

이러한 요청에는 사용자 지정 헤더가 포함되지 않으며 대신 대상 서버에서 허용 할 것인지 확인하기 위해 Access-Control-Request-Headers에 추가됩니다.

대상 서버가 수용 가능한 allow- 응답으로 응답하는 경우 후속 GET에 헤더가 포함됩니다.

0

달성하고자하는 바에 달려 있습니다.

강제로 캐시되지 않은 응답을 보내고 서버를 제어 할 수 없다면 위와 같은 가짜 쿼리 매개 변수를 추가하는 것이 좋습니다.

options = { 
    uri :`${SUPPORT_FEED_URI}?${new Date().getTime()}`, 
    headers : { 
     'Content-Type': 'application/x-www-form-urlencoded' 
    }, 
} 

'Cache-Control'헤더에 대한 자세한 내용은 여기에서 위로 대답을 참조하십시오. What's the difference between Cache-Control: max-age=0 and no-cache?