2011-11-23 2 views
0

이것은 연결 문제가 발생하는 곳의 코드입니다. HttpConnection은 입력 스트림에서 연결 obj로부터 응답을받지 못합니다.HttpConnection 메시지에서 Blackberry의 오류가 데이터 그램 (ConnectionBase) 수신. 데이터 그램 행 538

Datagram(ConnectionBase).receive (Datagram) 라인 도움이 될 예외를 게시 538

HttpConnection httpCon = null; 
    InputStream iStream = null; 
    String url = null; 
    String result = ""; 
    public GetXmlHttp(String str) 
    { 
     url=str; 
    } 
    public String RESULT() 
    {  
     try 
     { 
      httpCon = (HttpConnection)Connector.open(url); 
      httpCon.setRequestMethod(HttpConnection.GET); 
      iStream = httpCon.openInputStream();//error is here 

      int httpResponse = httpCon.getResponseCode(); 
      System.out.println("httpResponse code"+httpResponse); 
      System.out.println(httpResponse); 
      if(httpResponse != 200) 
      return null; 

      InputStreamReader in = new InputStreamReader(iStream); 
      StringBuffer sb=new StringBuffer(); 
      char[] ch=new char[1020]; 
      while(in.read(ch)!=-1) 
      { 
       sb.append(ch); 
      } 
     } 
} 
+3

예외를 게시하십시오. –

답변

0

하지만, allso가 HttpConnection에 대한 API 문서를 참고하십시오 발생하는 오류입니다. HttpConnection을 통해 가져 오기위한 샘플 코드가 있습니다. HttpConnection은 사용자와 최소한 중요한 차이가 있습니다. getResponseCode가 openInputStream 전에 호출되었습니다.

void getViaHttpConnection(String url) throws IOException { 
    HttpConnection c = null; 
    InputStream is = null; 
    int rc; 

    try { 
     c = (HttpConnection)Connector.open(url); 

     // Getting the response code will open the connection, 
     // send the request, and read the HTTP response headers. 
     // The headers are stored until requested. 
     rc = c.getResponseCode(); 
     if (rc != HttpConnection.HTTP_OK) { 
      throw new IOException("HTTP response code: " + rc); 
     } 

     is = c.openInputStream(); 
관련 문제