2017-12-30 52 views
1

WAS 환경에서 httpservlet (java)에 대한 게시를 시도 할 때 im이 null 응답을 얻는 이유를 알아 내는데 어려움이 있습니다.Java Servlet을 호출 할 때 Httpclient 응답이 null입니다.

IM이 로그인하려고하면 api를 호출하려고합니다. 응답 헤더를 받기를 원하지만, 응답이 없으면 응답을받지 못하게됩니다.

콘텐츠 유형 응용 프로그램/x-www-form-urlencoded; charset = UTF-8을 사용하여 양식 데이터로 매개 변수를 보내고 콘텐츠 형식을 정의하지 않은 쿼리 매개 변수로 보내려고했습니다.

두 경우 모두 로그인 할 수 있으며 브라우저에서 머리글 정보가있는 200 개의 응답을받는 중입니다.

내 전화

return this.http.post(this.contextRoot.getHost() + 'osa-kantoor-ws/api/auth/login?' + param1 + "&" + param2,null, this.httpOptions).map((res : Response) => { 
 
     localStorage.setItem('currentUser', JSON.stringify(username)); 
 
     return res; 
 
    });

내 헤더 정보가 이제 로컬 스토리지 항목이 설정되어

httpOptions = { 
 
    headers: new HttpHeaders({'Content-Type' : 'application/json', 'Accept': 'application/text'}), 
 
    params: {} 
 
    };

이지만, 재 스폰지 정보가 null입니다.

이 메신저 내 응답 헤더에서 브라우저 정보를 확인해 볼 때 나의

login() { 
 
    this.loginService.login(this.loginForm.value.userName,this.loginForm.value.password) 
 
     .subscribe(
 
     data => { 
 
      console.log(data); 
 
      this.router.navigate([this.returnUrl]); 
 
     }, 
 
     error => { 
 
      console.log(error); 
 
      this.loginfail = true; 
 
     }); 
 
    }

가입이다 나는 다음과 같은 정보를 얻을

enter image description here

는 사람이 나에게 무엇을 말할 수 나는 그리워 해? 는 config에 솔루션을 '응답'된다

아래 관찰을 추가

login(username: string, password: string) { 
 
    let param1: string = encodeURIComponent('userName') + '=' + encodeURIComponent(username); 
 
    let param2: string = encodeURIComponent('password') + '=' + encodeURIComponent(password); 
 
    let formParams: string = param1 + '&' + param2; 
 
    return this.http.post(this.contextRoot.getHost() + 'osa-kantoor-ws/api/auth/login', formParams, this.httpOptions).map(response=> { 
 
     localStorage.setItem('currentUser', JSON.stringify(username)); 
 
     console.log(response); 
 
     return response; 
 
    }); 
 
    }

+1

입니까? 무슨 일이 일어날 것으로 예상됩니까? 그리고 URL을 본문에 보내는 대신 URL의 일부로 자격 증명을 보내는 이유는 무엇입니까? 정말로 서버 로그에 암호가 나타나기를 원하지 않습니다. –

+0

나는 params를 url params로 보내면 아무것도 변하지 않는지 다른 접근법으로 사용했다. 원래 접근법은 본문에있는 양식 데이터로 전송하는 것이었다. 서블릿이 다른 정보를 제공하지 않고 헤더 정보 (예 : 쿠키)가있는 상태 200을 제공하지 않기 때문에 응답 본문은 비어 있습니다. –

+0

응답을 관찰하고 싶습니까? https://angular.io/guide/http#reading-the-full-response – Alex

답변

1

당신에게 AJT_82 감사 원래의 방법

입니다.

응답은 지금 내가 기대하는 것입니다. 기본 응답은 'body'를 관찰합니다.

내 HTTP의 설정은 이제

httpOptions = { 
 
    headers: new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8','Accept': 'application/xml'}), 
 
    observe: 'response' 
 
    };

이며, 내 대답은 지금은 서버가 응답 본문으로 다시 보내 무엇

enter image description here