Я хочу использовать Airnotifier в качестве сервера GCM. Сейчас сервер находится у меня дома. Я переправил порты: 8000, 8801, 5228-5230 на сервер. Я знаю, что сервер работает, потому что я могу подключиться к веб-интерфейсу из другого места. Но теперь в приложении, которое я хочу зарегистрировать маркер поэтому я использую этот код:Сервер Airnotifier 500 ответ JSON
String url = "http://URL:8801/api/v2/tokens";
JSONObject json =new JSONObject();
try {
json.put("device", "android");
json.put("token","tokennnn");
json.put("chanel","default");
} catch (JSONException e) {
e.printStackTrace();
}
BufferedReader br = null;
HttpURLConnection connection = null;
try {
connection = (HttpURLConnection) new URL(url).openConnection();
} catch (IOException e) {
e.printStackTrace();
}
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
try {
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("X-AN-APP-NAME", "appname");
connection.setRequestProperty("X-AN-APP-KEY", "appkey");
connection.setUseCaches(false);
} catch (ProtocolException e) {
e.printStackTrace();
}
OutputStreamWriter wr= null;
try {
wr = new OutputStreamWriter(connection.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
String jsonMessage = json.toString();
try {
wr.write(jsonMessage);
} catch (IOException e) {
e.printStackTrace();
}
String httpresponsecode = null;
String httpresponsemessage = null;
httpresponsecode = Integer.toString(connection.getResponseCode());
httpresponsemessage = connection.getResponseMessage();
Log.i(TAG, "JSON Message: " + jsonMessage);
Log.i(TAG, "HTTP Response: " + httpresponsecode + ": " + httpresponsemessage);
Я пытался несколько вещей, но это результат:
JSON Message: {"device":"android","token":"tokennnn","chanel":"default"}
HTTP Response: 500: Internal Server Error
А на сервере I получить это:
The problem on the server (IMAGE)
Я знаю, что есть некоторые проблемы JSON декодирования с питоном. Но я не могу понять проблему.
EDIT Найдено решение. См. Ответ в ответе на комментарии