auth_key 是必需的:Quickblox 错误

auth_key is required : Quickblox error

我正在使用 Quickblox REST API。当我尝试从 POSTMAN 运行 时,它给了我正确的输出。但是,当我通过 java 代码使用它时。它向我显示以下错误:

auth_key is required

这是我的 java 代码:

URL url = new URL("https://api.quickblox.com/session.json");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");

String current_date = dateFormat.format(cal.getTime());
Date newdt = dateFormat.parse(current_date);
long unixTime = newdt.getTime() / 1000;
String nonce = randomString(5);
String message ="application_id=XXXXX&auth_key=XXXXX&nonce=xxxxtimestamp=xxxx";
JSONObject arrayElement = new JSONObject();
arrayElement.put("application_id", "xxxxxx");
arrayElement.put("auth_key", "xxxxxxx");
arrayElement.put("nonce", nonce);
arrayElement.put("timestamp", unixTime);
arrayElement.put("signature", hmacDigest(message, secret, "HmacSHA1"));
conn.setRequestProperty("data", arrayElement.toJSONString());
conn.connect();

BufferedReader in = new BufferedReader(new   InputStreamReader(conn.getInputStream()));
String inputLine;
HashMap hmdata = new HashMap();
while ((inputLine = in.readLine()) != null) {
      hmdata.put("data", inputLine);
   }
in.close();

谁能帮我解决这个错误?

如果您作为 json 发送,则添加以下内容 header:

conn.setRequestProperty("Content-Type", "application/json");

因为服务器不理解您发送请求负载的格式