如何使用 Olingo (Odata) 进行 HTTP 认证服务调用

How to make an HTTP authenticated service call with Olingo (Odata)

我有一个要访问的 Web 服务,该服务受基本 HTTP 身份验证保护。

如何设置 OData 客户端以将身份验证发送到 Web 服务?

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

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

要访问 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)