4

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

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

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

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

1 回答 1

7

要访问 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)
于 2016-11-11T14:21:16.713 回答