我有一个受基本HTTP身份验证保护的Web服务。
如何设置ODataClient以将身份验证发送到Web服务?
ODataClient client = ODataClientFactory.getClient();
String iCrmServiceRoot = "https://example.dev/Authenticated/Service";
ODataServiceDocumentRequest odClientReq =
client.getRetrieveRequestFactory().getServiceDocumentRequest(iCrmServiceRoot);
答案 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)