2011-08-16 3 views
1

지금 나는 웹에서 이미지 다운로드 작업을하고 있습니다.이 경우 아래 코드와 같은 http 연결을 설정합니다.예기치 않은 응답 코드 : 403 Blackberry에서 이미지를 호출 할 때

HttpConnection connection = (HttpConnection) Connector.open(url, Connector.READ_WRITE); 
connection.setRequestMethod(HttpConnection.POST); 

나는 그것이 오류 예기치 않은 응답 코드를 보여 다른 그림에 대한 이미지 successfully.But를 표시 한 장의 사진 web.for에서 두 이미지를 호출 오전 : 내가 다운로드 할 수 있습니다이 문제가 occur.How 이유 403.I 이해하고 있지 않다 웹에서 이미지. 거기에 HttpConnection의 변경 사항을 수정해야합니다.

도와주세요.

+3

HTTP 403은 "금지됨"을 의미합니다. 두 번째 파일에 액세스 할 수있는 적절한 권한이 있습니까? –

+0

브라우저에서 호출 할 때 액세스합니다. Android 및 iphone에서 작동 중입니다. – Ajay

답변

-1

이 기능을 사용하여, 우리는 HTTP 연결에서 바이트를 얻을로,이 기능은 당신을 위해 그렇게 할 것 이미지로 그 바이트를 변환해야합니다, 단지 인수 이미지의 URL을 전달합니다

public static Bitmap connectServerForImage(String url) { 
    HttpConnection httpConnection = null; 
    DataOutputStream httpDataOutput = null; 
    InputStream httpInput = null; 
    int rc; 
    Bitmap bitmp = null; 
    try { 
     httpConnection = (HttpConnection) Connector.open(url); 
     rc = httpConnection.getResponseCode(); 
     if (rc != HttpConnection.HTTP_OK) { 
      throw new IOException("HTTP response code: " + rc); 
     } 
     httpInput = httpConnection.openInputStream(); 
     InputStream inp = httpInput; 
     byte[] b = IOUtilities.streamToBytes(inp); 
     EncodedImage hai = EncodedImage.createEncodedImage(b, 0, b.length); 
     int currentWidthFixed32 = Fixed32.toFP(hai.getWidth()); 
     int currentHeightFixed32 = Fixed32.toFP(hai.getHeight()); 
     int reqWidth = 48; 
     int reqHeight = 35; 
     int requiredWidthFixed32 = Fixed32.toFP(reqWidth); 
     int requiredHeightFixed32 = Fixed32.toFP(reqHeight); 
     int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32); 
     int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32); 
     hai = hai.scaleImage32(scaleXFixed32, scaleYFixed32); 
     return hai.getBitmap(); 
     } catch (Exception ex) { 
      System.out.println("URL Bitmap Error........" +url+ ex.getMessage()); 
     } finally { 
      try { 
       if (httpInput != null) 
        httpInput.close(); 
       if (httpDataOutput != null) 
        httpDataOutput.close(); 
       if (httpConnection != null) 
        httpConnection.close(); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
     return bitmp; 
     } 
0

실제 전화로 테스트 했습니까? 아니면 에뮬레이터에서 테스트 했습니까?

에뮬레이터를 사용하는 경우 에뮬레이터를 인터넷에 연결하도록 구성했는지 확인하십시오. 기본적으로 구성되지 않습니다.
BlackBerry emulator not connecting to internet

관련 문제