2011-12-12 2 views
1

실제 장치에서 GPRS (모바일 네트워크)를 통해 URL의 HttpConnection을 만들려고했으나 데이터를 반환하지 않지만 코드가 잘 작동하는 동일한 코드가 와이어리스를 통해 잘 작동합니다. 시뮬레이터 내 코드GPRS (모바일 네트워크)를 통한 HttpConnection

public static String getHttpUTFResponse(String url) { 
    HttpConnection connection = null; 
    byte responseData[] = null; 
    try { 
     connection = (HttpConnection) new ConnectionFactory() 
       .getConnection(url).getConnection(); 
     int len = (int) connection.getLength(); 
     System.out.println(len); 
     if (len != -1) { 
      responseData = new byte[len]; 
      DataInputStream dis; 
      dis = new DataInputStream(connection.openInputStream()); 
      dis.readFully(responseData); 
      dis.close(); 
     } 
    } catch (IOException e) { 
     System.out.println("Connection Error"); 
    } finally { 
     if (connection != null) { 
      try { 
       connection.close(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      connection = null; 
     } 

    } 
    if (responseData != null) { 
     try { 
      return new String(responseData,"UTF-8"); 
     } catch (UnsupportedEncodingException e) { 
      e.printStackTrace(); 
      return null; 
     } 
    } else { 
     return null; 
    } 
} 

주 : 장치 브라우저가 잘 작동하고 BB 서비스는 나는이 대답에 내 의견을 이동하고 하나

+0

당신이 코드를 디버깅 있나요? 예외가 있습니까? 줄 번호는 무엇입니까? – Vimal

+0

이 줄에서 멈 춥니 다. int len ​​= (int) connection.getLength(); 그 후 len은 (-1)을 반환하고 예외는 없습니다 – JustMe

+0

** BES **에 대해서는 deviceside = false, connectionUID = "'** BIS ** 및 " "; deviceside = false"'접미사가 있습니까? * 연결 URL에? – Vimal

답변

1

에 감사를 등록 :

Blackb에서 erry은 wireless/gprs/3g/simulator 꽤 도전을 위해, 당신이 가지고 있는지 확인하십시오, 당신은 연결 URL 장치 GPRS/3G를 들어

  • ";interface=wifi"을 접미사했는지 확인하십시오, 아래의 포인터 장치에 WiFi를 들어
    1. 하십시오 연결 URL을 설정 연결 URL에 BES

    자세히 설명 explanati에 대한 BIS 및 ";deviceside=false"에 대한 ";deviceside=false;connectionUID="을 접미사 에에서 찾을 수 있습니다 :

    1. Need Clarification ---- Http Connection/GPRS
    2. How to configure an IT Policy on the BlackBerry Enterprise Server to allow only the Internet Browser on the BlackBerry smartphone
    3. Internet Connectivity (APN?)
    4. Tag: APN
    5. Different ways to make an HTTP or socket connection

    는 편집 : 링크 (5)는 OP

    0,123,516 유용했다
  • 0

    이 시도 .. 이것이 당신이

    getWap2Uid(); 
          String url = "your url"; 
    
          if(DeviceInfo.isSimulator() == true) 
          { 
           conn = (StreamConnection) Connector.open(url+ ";deviceside=true"); 
          } 
          else 
          { 
          if (uid != null) 
          { 
           //open a WAP 2 connection 
           conn = (StreamConnection) Connector.open(url + ";deviceside=true;ConnectionUID=" + uid); 
    
          } 
          else 
          { 
           //Consider another transport or alternative action. 
           conn = (StreamConnection) Connector.open(url +";deviceside=true;interface=wifi"); 
    
    
          } 
          } 
    

    getWap2Uid 기능이 여기 시뮬레이터, 와이파이 및 GPRS 연결을 감지하는 데 도움이 될 것입니다

    public static String uid ; 
    
    static String getWap2Uid() { 
    
        ServiceRecord[] records = ServiceBook.getSB().findRecordsByCid("WPTCP"); 
        for (int i = 0; i < records.length; i++) 
        { 
         ServiceRecord serviceRecord = records[i]; 
         String recordName = serviceRecord.toString().toUpperCase(); 
         if (serviceRecord.isValid() && !serviceRecord.isDisabled() && 
           serviceRecord.getUid() != null && serviceRecord.getUid().length() != 0 && 
           recordName.indexOf("WAP2")!=-1) 
    
         { 
          uid = serviceRecord.getUid(); 
           EventLogger.logEvent(EventLogID, new String("getWap2Uid, UID="+uid).getBytes()); 
          return uid; 
         } 
        } 
        return null; 
    
    } 
    
    관련 문제