1
에 너무 많은 리디렉션 :java.net.ProtocolException : 나는 URL에서 동영상을 다운로드하는 것을 시도하고이 예외를 얻고 안드로이드
java.net.ProtocolException: Too many redirects
아래의 내 코드입니다. 여기서 내가 뭘 잘못하고 있니?
private void savePrivateExternalFile(String fileURL, String fName)
{
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
HttpURLConnection connection = null;
URL url = null;
long startTime = System.currentTimeMillis();
try
{
url = new URL(fileURL);
connection = (HttpURLConnection) url.openConnection();
connection.addRequestProperty(BsharpConstant.WEB_SERVICES_COOKIES, cookie);
connection.setDoOutput(true);
connection.connect();
File folderDir = null;
if (clickedItemId == 0) folderDir = new File(getExternalFilesDir("Product") + "/Brochure");
else folderDir = new File(getExternalFilesDir("Product") + "/Videos");
File file = new File(folderDir, fName);
if (file.exists()) file.delete();
if (folderDir.isDirectory() || folderDir.mkdirs())
{
InputStream inputStream = connection.getInputStream(); // Exception is thrown here !!
FileOutputStream fileOutputStream = new FileOutputStream(folderDir + "/" + fName);
int len = 0;
byte[] buffer = new byte[1024];
if (clickedItemId == 1)
{
while ((le = inputStream.read(buffer)) != -1)
{
fileOutputStream.write(buffer, 0, len);
}
}
else
{
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 1024 * 50);
while ((len = bufferedInputStream.read(buffer)) != -1)
{
fileOutputStream.write(buffer, 0, len);
}
bufferedInputStream.close();
Log.i("Download", "download completed in " + ((System.currentTimeMillis() - startTime)/1000) + " sec");
}
fileOutputStream.close();
inputStream.close();
editSharedPreferences.putString(fName, fName);
editSharedPreferences.commit();
}
else
{
Toast.makeText(getApplicationContext(), BsharpUserMessage.UNABLE_TO_CREATE_THE_FOLDER, Toast.LENGTH_LONG).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
로그 캣 :
01-07 14:21:36.163: W/System.err(25391): java.net.ProtocolException: Too many redirects
01-07 14:21:36.163: W/System.err(25391): at l libcore.net.http.HttpURLConnectionImpl.processResponseHeaders(HttpURLConnectionImpl.java:368)
01-07 14:21:36.163: W/System.err(25391): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:292)
01-07 14:21:36.163: W/System.err(25391): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
01-07 14:21:36.173: W/System.err(25391): at com.abc.xyz.ProductBrochureActivity.savePrivateExternalFile(ProductBrochureActivity.java:231)
01-07 14:21:36.173: W/System.err(25391): at com.abc.xyz.ProductBrochureActivity.access$7(ProductBrochureActivity.java:200)
01-07 14:21:36.173: W/System.err(25391): at com.abc.xyz.ProductBrochureActivity$2.run(ProductBrochureActivity.java:140)
01-07 14:21:36.173: W/System.err(25391): at java.lang.Thread.run(Thread.java:856)
`
여기 로그 캣을 게시하시기 바랍니다. – rup35h
분명히 이것은 310 오류 코드입니다. 오류는 서버에있을 수 있습니다. – Manitoba
@ 매니토바 정확한 문제는 무엇을해야합니까? 이걸 설명해 주시겠습니까? 당신의 친절에 감사드립니다. – user3154663