【问题标题】:How to make an HTTP authenticated service call with Olingo (Odata)如何使用 Olingo (Odata) 进行 HTTP 身份验证服务调用
【发布时间】:2017-03-25 19:12:58
【问题描述】:
我有一个受基本 HTTP 身份验证保护的 Web 服务可供访问。
如何设置 ODataClient 以将身份验证发送到 Web 服务?
ODataClient client = ODataClientFactory.getClient();
String iCrmServiceRoot = "https://example.dev/Authenticated/Service";
ODataServiceDocumentRequest odClientReq =
client.getRetrieveRequestFactory().getServiceDocumentRequest(iCrmServiceRoot);
【问题讨论】:
标签:
java
odata
http-authentication
olingo
【解决方案1】:
要访问 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)