Galaxy Nexus が今日届きました。最初に行った作業の 1 つは、自分のアプリをその上にロードして、友人にデモンストレーションできるようにすることでした。その機能の一部には、Google リーダーからの RSS フィードのインポートが含まれます。ただし、これを試してみると、405 Method Not Allowed エラーが発生しました。
この問題は Ice Cream Sandwich 固有の問題です。添付したコードは、Gingerbread と Honeycomb で正常に動作します。GET リクエストが魔法のように POST リクエストに変わるとき、接続が確立される瞬間までエラーを追跡しました。
/**
* Get the authentication token from Google
* @param auth The Auth Key generated in getAuth()
* @return The authentication token
*/
private String getToken(String auth) {
final String tokenAddress = "https://www.google.com/reader/api/0/token";
String response = "";
URL tokenUrl;
try {
tokenUrl = new URL(tokenAddress);
HttpURLConnection connection = (HttpURLConnection) tokenUrl.openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("Authorization", "GoogleLogin auth=" + auth);
connection.setRequestProperty("Content-Type","application/x-www-form-urlendcoded");
connection.setUseCaches(false);
connection.setDoOutput(true);
Log.d(TAG, "Initial method: " + connection.getRequestMethod()); // Still GET at this point
try {
connection.connect();
Log.d(TAG, "Connected. Method is: " + connection.getRequestMethod()); // Has now turned into POST, causing the 405 error
InputStream in = new BufferedInputStream(connection.getInputStream());
response = convertStreamToString(in);
connection.disconnect();
return response;
}
catch (Exception e) {
Log.d(TAG, "Something bad happened, response code was " + connection.getResponseCode()); // Error 405
Log.d(TAG, "Method was " + connection.getRequestMethod()); // POST again
Log.d(TAG, "Auth string was " + auth);
e.printStackTrace();
connection.disconnect();
return null;
}
}
catch(Exception e) {
// Stuff
Log.d(TAG, "Something bad happened.");
e.printStackTrace();
return null;
}
}
この問題を引き起こしている可能性のあるものはありますか? この問題を回避するために、この関数をより適切にコーディングできますか?
よろしくお願いします。