2013-12-20 2 views
1

저는 this question에 설명 된 방법을 사용하여 HTTP 요청에 특정 헤더를 추가합니다. 하지만 인터셉터가 자신의 업무를 수행하도록 코드를 변경해야하는 방법을 이해할 수 없습니다. 현재 나는이 같은 것을 사용하고 있습니다 :HTTP에 헤더를 정확하게 추가하려면 어떻게해야합니까? AndroidAnnotations로 요청을 받으시겠습니까?

@RestService 
ImwizardClient imwizardClient; 

//some code 

return imwizardClient.getAllCategories(); 

getAllCategories() 요청을받을 수 있습니다 방법이다. 요청이 올바르게 작동하지만 사용자 정의 헤더를 추가하지 않습니다. 그렇다면 무엇을 바꾸어야합니까?

답변

1

here과 같이 RestService 클래스에 인터셉터가 정의되어 있습니까?

@Rest(interceptors = { HttpBasicAuthenticatorInterceptor.class }) 
public interface ImwizardClient { 
// ... snipped 
} 

또는 this thread에 게시 된 해결 방법은 안정적으로 작동하는 것 같습니다. RestService 클래스 용 사용자 정의 MessageConverter를 정의하십시오.

public class GsonWithHeadersConverter extends GsonHttpMessageConverter { 

@Override 
    protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { 
     setHeaders(outputMessage); //My method to put the additional headers :) 
     super.writeInternal(o, outputMessage); 
    } 

}

관련 문제