1
我正在使用Quickblox REST API。當我試圖從POSTMAN運行時,它給了我適當的輸出。但是,當我通過我的java代碼使用它。它顯示我以下錯誤:需要auth_key:Quickblox錯誤
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();
任何人可以幫助我解決這個問題?
是明白的。現在工作。我的問題是發送輸入到休息客戶端。所以,我已經使用outputstream,代碼現在工作正常。將「接受」更改爲「content-Type」,以便在json對象中發送數據 –