如何使用Olingo(Odata)进行HTTP身份验证的服务调用

时间:2016-11-11 14:21:17

标签: java odata http-authentication olingo

我有一个受基本HTTP身份验证保护的Web服务。

如何设置ODataClient以将身份验证发送到Web服务?

ODataClient client = ODataClientFactory.getClient();
String iCrmServiceRoot = "https://example.dev/Authenticated/Service";

ODataServiceDocumentRequest odClientReq = 
    client.getRetrieveRequestFactory().getServiceDocumentRequest(iCrmServiceRoot);

1 个答案:

答案 0 :(得分:4)

要访问Web服务,您只需将基本HTTP身份验证添加到配置中,如下所示:

ODataClient client = ODataClientFactory.getClient();

// add the configuration here
client.getConfiguration()
    .setHttpClientFactory(new BasicAuthHttpClientFactory("[username]", "[password]"));

String iCrmServiceRoot = "https://example.dev/Authenticated/Service";
ODataServiceDocumentRequest odClientReq = 
    client.getRetrieveRequestFactory().getServiceDocumentRequest(iCrmServiceRoot)