मेरा गैलेक्सी नेक्सस आज पहुंचा, और मैंने पहली चीजों में से एक को अपने ऐप को लोड करना था ताकि मैं इसे अपने दोस्तों को प्रदर्शित कर सकूं। इसकी कार्यक्षमता के भाग में Google रीडर से आरएसएस फ़ीड आयात करना शामिल है। हालांकि, इस कोशिश करने पर, मुझे 405 विधि अनुमत त्रुटियों की अनुमति नहीं मिली थी।एंड्रॉइड 4.0 आईसीएस बदलते हुए HttpURLConnection 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;
}
}
क्या कोई समस्या है जो इस समस्या का कारण बन सकती है? क्या इस समस्या से बचने के लिए यह कार्य बेहतर कोडित किया जा सकता है?
अग्रिम में बहुत धन्यवाद।
नहीं HTTP के तरीके के लिए जाना। उस रेखा को हटाने से कोई फर्क नहीं पड़ता। –
ठीक है, तो आप HttpClient के साथ जाने का भी प्रयास कर सकते हैं। –
@ माइकल डोड: अद्यतन अनुभाग –