2017-11-17 13 views
0

asp net 코어에로드 된 각 클라이언트 응용 프로그램이 있습니다. asp net core에서 각도 응용 프로그램으로 오는 초기 요청은 몇 가지 헤더를 제공합니다. 어떻게 헤더를 캡처하여 나중에 다시 사용할 수 있습니까? 머리글을 캡처하거나 각도에 따라 호출을 가로 채기가 가능합니다. 어떻게 초기 응답의 머리글을 캡처 할 수 있습니까? 제발 제안 해주세요. GET 헤더Asp core -Angular 2 서버에서 처음 렌더링 할 때의 머리글 캡쳐

답변

0

예 헤더

http 
    .post('/api/items/add', body, { 
    headers: new HttpHeaders().set('Authorization', 'my-auth-token'), 
    }) 
    .subscribe(); 

HttpHeaders 클래스는 불변으로 POST의

http 
    .get<MyJsonData>('/data.json', {observe: 'response'}) 
    .subscribe(resp => { 
    // Here, resp is of type HttpResponse<MyJsonData>. 
    // You can inspect its headers: 
    console.log(resp.headers.get('X-Custom-Header')); 
    // And access the body directly, which is typed as MyJsonData as requested. 
    console.log(resp.body.someField); 
    }); 

예 그래서 각 세트() 새로운 인스턴스를 반환하고 변경을 적용한다.

자세한 내용

편집 https://angular.io/guide/http : 나는 당신이 나중에 사용하여 뜻 확실하지 오전 - 페이지를 새로 고침 후에 필요하면 아마도 당신이 SessionStorage 또는하려면 로컬에 저장할 수 있습니다.

확인 : Accessing the web page's HTTP Headers in JavaScript 도움이