私はアプリを作った。 GoogleのC2DMサービスを使用するAndroid用私は いくつかのチュートリアルからサーバーシミュレータを作ったとうまく動作します。私の 問題は、私はJava Servletを構築しようとしました。 Androidデバイス からメッセージを受信して登録IDを保存しますが、 https POSTリクエストをGoogle C2DMサーバーに送信しようとすると、常に はSocketTimeoutExceptionを取得します。フェッチ中のタイムアウト: https://android.clients.google.com/c2dm/send。 Androidの デバイスで同じものが動作している場合、なぜこのようなことが起こっているのかわかりません。コードは次のとおりです。C2DMでHTTP PostにSocketTimeoutExceptionを与える
//The AuthToken from Google Client Login
String auth_key = TOKEN;
StringBuilder postDataBuilder = new StringBuilder();
//some parameters to pass, I've checked and it's correct, it's working
//with Fiddler
postDataBuilder.append(PARAM_REGISTRATION_ID).append("=").append(REGISTRATION_ID);
postDataBuilder.append("&").append(PARAM_COLLAPSE_KEY).append("=").append("0");
postDataBuilder.append("&").append("data.payload").append("=").append(URLEncoder.encode(message, UTF8));
byte[] postData = postDataBuilder.toString().getBytes(UTF8);
URL url = new URL("https://android.clients.google.com/c2dm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
conn.setRequestProperty("Content-Length",Integer.toString(postData.length));
conn.setRequestProperty("Authorization", "GoogleLogin auth="+auth_key);
OutputStream out = conn.getOutputStream();
out.write(postData);
out.close();
int responseCode = conn.getResponseCode();
//here comes the error processing, but I can't reach it, because of
//the exception.
if (responseCode == 401 || responseCode == 403) {
//....
}
ありがとうございます。