2

isomorphic-fetch를 사용하여 일부 자격 증명을 전달하는 게시물 요청을 수행하려고합니다. 지금 가지고있는 코드는 다음과 같습니다.isomorphic-fetching을 사용하는 기본 인증

export default function fetchJson(url: string, options: any) { 
    options.headers = (<any>Object).assign({ 
    'Accept': 'application/json', 
    'Content-Type': 'application/json' 
    }, options.headers); 
    return fetch(url, options) 
    .then(checkStatus) 
    .then(parseJSON); 
} 

export function fetchLogs(dispatch_ok: any, dispatch_error: any) { 
     var URL = "http://server_address:8080/api/getlogs/"; 
     return fetchJson(URL, { 
         method: 'get', 
         credentials: 'include', 
         headers: { 
          Authorization: 'Basic '+window.btoa('user:passwd'), 
         } 
      }).then((data: any) => { 
       if (data.results.length != 0) { 
        dispatch_ok(data.results); 
       } else { 
        dispatch_error("No logs could be retrieved"); 
       } 
      }).catch((error: any) => { 
       dispatch_error(error.message); 
      }); 
} 

이 코드는 로그인 페이지로 리디렉션되기 때문에 작동하지 않습니다. 이 작품을 만드는 방법에 대한 아이디어가 있습니까? 와

답변

2

기본 인증

당신이 미세하게됩니다이 코드를 동형은 페치. 즉, 인증 헤더를 잘 게시합니다.

기타

리디렉션 논리가 손상되었을 가능성이 큽니다.

+0

어떻게 디버깅 할 수 있는지에 대한 아이디어가 있습니까? – user3091275