2

我想要使用同构获取来传递某些凭据。这里是我现在的代码:具有同构获取的基本身份验证

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