尝试连接到数据市场 returns 异常

Trying to connect to datamarket returns exception

我正在尝试连接到 Azure 数据市场,它是一个 odata 存储库。我正在使用最新的 Olingo 库 r4.2.0。以下代码:

String serviceUrl = "https://api.datamarket.azure.com/DataGovUK/MetOfficeWeatherOpenData/v1/";

ODataClient client = ODataClientFactory.getClient();
ODataServiceDocumentRequest req = client.getRetrieveRequestFactory().getServiceDocumentRequest(serviceUrl);
req.setAccept("application/json;application/xml;odata.metadata=full");
req.setContentType("application/json;application/xml;odata.metadata=full");
ODataRetrieveResponse res = req.execute();

returns异常

 org.apache.olingo.client.api.communication.ODataClientErrorException: null [HTTP/1.1 415 Unsupported Media Type]

服务器returns:

<?xml version="1.0" encoding="utf-8"?>
<m:error mlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
   <m:code />
   <m:message xml:lang="en-US">
       Unsupported media type requested.
   </m:message>
</m:error>

有人试图通过此库或其他 Java?

连接到 Azure 数据市场

尝试将请求 headers Accept & Content-Type 设置为仅 JSONXML,而不是两者。请看下面。

req.setAccept("application/json");
req.setContentType("application/json;odata.metadata=full");

或者

req.setAccept("application/atom+xml,application/xml");
req.setContentType("application/atom+xml,application/xml;odata.metadata=full");

并申请授权

req.addCustomHeader("Authorization", "Basic " + getAccountKey());

其他 Whosebug post 中描述的帐户密钥是:

public String getAccountKey()
{
    String accountKey = "My Microsoft Azure Account Key";
    byte[] accountKeyBytes = Base64.encodeBase64((accountKey + ":" + accountKey).getBytes());
    String accountKeyEnc = new String(accountKeyBytes);
    return accountKeyEnc;
}