|
[云开发]
java连接apicloud数据库问题。
[复制链接]
用java连接apicloud数据库,一直抱以下错误:{
"code": 0,
"status": 0,
"msg": "invalid request."
}
另外从论坛里搜了别人的代码测试,还是抱这个问题,请大家指正。
论坛看的代码如下:
public static String apidata() throws NoSuchAlgorithmException,
ClientProtocolException, IOException {
String appid = "xxxxxxxxxx";
String appkey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
HttpClient client = HttpClients.createDefault();
HttpGet get = new HttpGet("https://d.apicloud.com/mcm/api/user/");
get.addHeader("X-APICloud-AppId", appid);
long time = System.currentTimeMillis();
get.addHeader("X-APICloud-AppKey", getSha1(appid + "UZ" + appkey + "UZ"
+ time) + "." + time);
HttpResponse response = client.execute(get);
InputStream is = response.getEntity().getContent();
// 创建包装流
BufferedReader br = new BufferedReader(new InputStreamReader(is));
// 定义String类型用于储存单行数据
String line = null;
// 创建StringBuffer对象用于存储所有数据
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line);
}
System.out.println("data:" + sb.toString());
return sb.toString();
}
public static String getSha1(String decript) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-1");
digest.update(decript.toLowerCase().getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
if (shaHex.length() < 2) {
hexString.append(0);
}
hexString.append(shaHex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
|
|