2017-04-11 6 views
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(); 

誰が私はこのエラーを解決するのに役立つことはできますか?

答えて

0

あなたはJSONとして送信する場合、次のヘッダーを追加します。サーバーは、要求のペイロード

+1

はいを​​送るどのような形式で理解していないため

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

が。今働いている。私の問題は、残りのクライアントに入力を送ることでした。だから、私はoutputstreamを使用して、コードは今うまく動作しています。 jsonオブジェクトでデータを送信するために「Accept」から「content-Type」に変更されました –

関連する問題