【发布时间】:2017-06-28 12:16:45
【问题描述】:
我正在使用 groovy 制作 REST API,我正在提供 Real Shop 集成 Rest Api。但是我得到了soapui和代码连接重置错误。那么你们能帮我解决这个问题吗?
真正的是getSignature方法:
private String getSignature(Map params) throws NoSuchAlgorithmException, InvalidKeyException {
String plainText = "GET" + "\n" + params.endpointUrl + "\n" + "" + "\n" + timess
Mac mac = Mac.getInstance("HmacSHA256")
SecretKeySpec secretKeySpec = new SecretKeySpec(params.password.getBytes(), "HmacSHA256")
mac.init(secretKeySpec)
byte[] rawHmac = mac.doFinal(plainText.getBytes())
return DatatypeConverter.printHexBinary(rawHmac)
}
https://www.real.de/api/v1/?page=rest-api
我的代码:
@Override
protected Map getCategories(Map params) {
params.authentication.timestamp = (System.currentTimeMillis() /1000L)
String signature = getSignature(params.authentication)
def client = new RESTClient( params.authentication.endpointUrl )
Map response = client.get( path : 'categories',
headers: [
'accept': application/json,
'hm-client' : params.authentication.apiKey,
'hm-signature' : signature,
'hm-timestamp' : params.authentication.timestamp,
//'sslTrustAllCerts': true
]
)
assert response.status == 200 // HTTP response code
println response.getData()
return response
}
【问题讨论】: