2011-09-28 2 views
0

나는 블랙 베리 모바일을위한 첫 번째 앱을 만들려고 노력하고 있는데, 새로운 @ 모바일 개발이며, 내 앱을 내 webiste 나머지 API와 연결하는 정확한 방법을 찾지 못한다. 사전에블랙 베리 앱을 내 웹 사이트의 휴식 API에 어떻게 연결할 수 있습니까?

고맙습니다 : D

+0

정확히 당신이 원하는 무엇을? 그것을 분명히 설명 해주십시오. 웹 서비스에 액세스하고 싶습니까, 아니면 xml을 파싱하고 싶습니까? –

+0

XML 및 JSON 출력을 모두 사용하여 웹 사이트에 REST API를 만들었습니다. 블랙 베리 앱을 통해 이들 중 하나에 액세스하고 싶지만 어디서부터 시작해야할지 또는 무엇을 검색해야하는지 전혀 모릅니다. –

답변

1
HttpConnection conn = null; 
    InputStream is = null; 
    ByteArrayOutputStream bos = null; 
    String response = null; 
    String connectionURL = null; 



    try { 

     connectionURL = "THIS CONTAIN YOUR API URL" 

     conn = (HttpConnection) Connector.open(connectionURL); 
     conn.setRequestProperty("Content-Type","application/json"); 
     System.out.println("Response code : "+conn.getResponseCode()); 

     if(conn.getResponseCode() == HttpConnection.HTTP_OK) 
     { 

      is = conn.openInputStream(); 
      int ch=-1; 
      bos = new ByteArrayOutputStream(); 
      while((ch = is.read())!=-1) 
      { 
       bos.write(ch); 
      } 
      response = new String(bos.toByteArray()); 
      System.out.println("Response : "+response); 
     } 
    } catch (Exception e) 
    { 
     System.out.println("Exception .."+e); 

    }finally 
    { 

      if(conn != null) 
       conn.close(); 
      if(is != null) 
       is.close(); 
      if(bos != null) 
       bos.close(); 
    }