我有一个odata端点,可以进行HMAC身份验证。基本上是常规
Http URL url = new URL(uri);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
String currentUTCTime = getCurrentUTCTime();
Map<String, String> headers = new LinkedHashMap<>();
headers.put("x-csod-date", currentUTCTime);
headers.put("x-csod-session-token", sessionToken);
con.setRequestProperty("x-csod-date", currentUTCTime);
con.setRequestProperty("x-csod-session-token", sessionToken);
String stringToSign = constructStringToSign(con.getRequestMethod(), headers, url.getPath());
String sig = signString512(stringToSign, sessionSecret);
con.setRequestProperty("x-csod-signature", sig);
System.out.println("signation is : "+sig);
//*********
con.setConnectTimeout(90000);
con.setReadTimeout(99000);
int status = con.getResponseCode();
我试图通过apache olingo客户端来模仿
ODataClient client = ODataClientFactory.getV4();
String serviceRoot = "https://knet.csod.com/services/api/x/odata/api/views/vw_rpt_transcript";
URI url=new URI(serviceRoot);
ODataRawRequest req=
client.getRetrieveRequestFactory().getRawRequest(url);
req.setXHTTPMethod("GET");
String currentUTCTime = getCurrentUTCTime();
req.addCustomHeader("x-csod-date",currentUTCTime);
req.addCustomHeader("x-csod-session-token",sessionToken);
Map<String, String> headers = new LinkedHashMap<>();
headers.put("x-csod-date", currentUTCTime);
headers.put("x-csod-session-token", sessionToken);
String stringToSign = constructStringToSign(req.getMethod().name(), headers, serviceRoot);
String sig = signString512(stringToSign, sessionSecret);
req.addCustomHeader("x-csod-signature",sig);
ODataResponse res=req.execute();
第一个http代码有效,但是我得到了回应,但是我的odata代码给出了401未经授权的错误
线程“主”中的异常 org.apache.olingo.client.api.communication.ODataClientErrorException: (401)CSOD未经授权的异常:检查您的凭据。 [HTTP / 1.1 401未经授权] org.apache.olingo.client.core.communication.header.ODataErrorResponseChecker.checkResponse(ODataErrorResponseChecker.java:73) 在 org.apache.olingo.client.core.communication.request.AbstractRequest.checkResponse(AbstractRequest.java:53) 在 org.apache.olingo.client.core.communication.request.AbstractODataRequest.doExecute(AbstractODataRequest.java:324) 在 org.apache.olingo.client.core.communication.request.retrieve.ODataRawRequestImpl.execute(ODataRawRequestImpl.java:66) 在GetClient.main(GetClient.java:180)