Java 需要验证密钥:Quickblox错误

Java 需要验证密钥:Quickblox错误,java,rest,quickblox,Java,Rest,Quickblox,我正在使用Quickblox REST API。当我试图从邮递员那个里跑出来时,它给了我正确的输出。但是,当我通过java代码使用它时。它向我显示以下错误: 需要验证密钥 以下是我的java代码: URL url = new URL("https://api.quickblox.com/session.json"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("

我正在使用Quickblox REST API。当我试图从邮递员那个里跑出来时,它给了我正确的输出。但是,当我通过java代码使用它时。它向我显示以下错误:

需要验证密钥

以下是我的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格式发送,请添加以下标题:

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

因为服务器不了解您以何种格式发送请求的有效负载,如果您以json形式发送,则添加以下标头:

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

因为服务器不了解您以何种格式发送请求的有效负载

yes。现在工作。我的问题是向rest客户端发送输入。所以,我使用了outputstream,代码现在运行良好。将json objectyes中发送数据的“接受”更改为“内容类型”。现在工作。我的问题是向rest客户端发送输入。所以,我使用了outputstream,代码现在运行良好。将用于在json对象中发送数据的“接受”更改为“内容类型”