2013-10-09 8 views
0

다음 Android 코드에서 getInputStream으로부터 EOFException을받습니다.JSON 요청을 보낼 때 getInputStream이 EOFException을 던졌습니다.

private void downloadUrl() { 
    HttpsURLConnection conn = null; 
    DataOutputStream printout = null; 
    try { 
     try { 
      conn = (HttpsURLConnection) new URL("some url").openConnection(); 
      conn.setRequestMethod("POST"); 
      conn.setDoInput(true); 
      conn.setDoOutput(true); 
      conn.setUseCaches(false); 
      conn.setAllowUserInteraction(false); 
      conn.setRequestProperty("Accept", "application/json"); 
      conn.setRequestProperty("Content-Type", "application/json; charset=utf-8"); 
     } 
     catch (ProtocolException e){ 
     } 

     JSONObject jsonReq = new JSONObject(); 
     jsonReq.put("userID", "id"); 
     jsonReq.put("password", "1234"); 

     OutputStream output = conn.getOutputStream(); 
     try { 
      OutputStreamWriter wr = new OutputStreamWriter(output); 
      wr.write(URLEncoder.encode(jsonReq.toString(),"utf-8")); 
      wr.flush(); 
      wr.close(); 
     } 
     catch (IOException e) { 
     } 

     InputStream in = conn.getInputStream(); //I get EOFException here 
     try { 
      BufferedReader rd = new BufferedReader(new InputStreamReader(in)); 
      String responseSingle = null; 
      while ((responseSingle = rd.readLine()) != null) { 
       response = response + responseSingle; 
      } 
      rd.close(); 
     } 
     catch (IOException e) { 
     } 
     finally { 
      if (in != null) 
      in.close(); 
     } 
    } 
    catch (IOException e){ 
    } 
    catch (JSONException e) { 
    } 
    finally{ 
     if(conn!=null) 
      conn.disconnect(); 
    } 
} 

이 예외의 원인은 무엇입니까? 파일 또는 스트림의 끝의 끝이 입력하는 동안 예기치 않게 도달 한

신호 :

답변

관련 문제