마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

Service 에서 Http통신할때 500 Error가 계속 뜹니다...ㅠㅠ

0 추천

퍼미션도 잘걸어줬도 경로도 잘확인했고..

앱에서 HttpURLConnection 를 이용해서 접속하려하면 responseCode 가 500 에러를 찍네요...

소스는 아래와 같이했습니다..

p.s HttpURLConnection.HTTP_OK 를 무시하고 해봤더니 FileNotFound가 뜨네요...파일은 잘있는데 어찌된건지..

try{
			URL url = new URL(URL+"?getOcode="+ocode);
			
			HttpURLConnection conn = (HttpURLConnection)url.openConnection();
			if(conn != null) {
				conn.setDoOutput(true); 
			    conn.setDoInput(true);
			    conn.connect();
			    
				Log.e("LOG4 getResponseCode",  conn.getResponseCode()+" <==");
				
				if(conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
					isr = new InputStreamReader(conn.getInputStream(), "EUC-KR") ;
					br = new BufferedReader(isr);
					while(true) {
						String line = br.readLine();
						Log.e("LOG4 line",  line+" <===");
						if(line == null) {
							break;
						}
						sBuffer.append(line+"\n");
						line = null;
					}
					conn.disconnect();
				}
			}

		}catch(Exception e){
			Log.e("LOG4 error", e.toString());
			e.printStackTrace();
		}

 

아직도초보 (3,030 포인트) 님이 2014년 9월 30일 질문
아직도초보님이 2014년 9월 30일 수정
서버 쪽을 보셔야 할것 같은데요?

1개의 답변

+1 추천
 
채택된 답변
500번 에러면 서버 내부 에러 입니다.

 

응답 코드가 HttpURLConnection.HTTP_OK (200번)이 아닐 경우

 

conn.getErrorStream()으로 에러 내용을 가져와서 보시면

 

문제를 해결하는데 좀 더 도움이 될 것입니다.
원조안드로이드 (58,190 포인트) 님이 2014년 10월 1일 답변
아직도초보님이 2014년 10월 1일 채택됨
소중한 답변 감사합니다! ^^
error stream을 읽었는데.... 다음과 같은 에러가 나오는데 어떻게 해야할지를 몰라서 글을 남겨봅니다...ㅠㅜ

<!DOCTYPE html><html>    <head>        <title>런타임 오류</title>        <meta name="viewport" content="width=device-width" />        <style>         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}          p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }         pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}         .marker {font-weight: bold; color: black;text-decoration: none;}         .version {color: gray;}         .error {margin-bottom: 10px;}         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }         @media screen and (max-width: 639px) {          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }         }         @media screen and (max-width: 479px) {          pre { width: 280px; }         }        </style>    </head>    <body bgcolor="white">            <span><H1>'/' 응용 프로그램에 서버 오류가 있습니다.<hr width=100% size=1 color=silver></H1>            <h2> <i>런타임 오류</i> </h2></span>            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">            <b> 설명: </b>서버에서 응용 프로그램 오류가 발생했습니다. 이 응용 프로그램의 현재 사용자 지정 오류 설정이 보안상 이유로 응용 프로그램 오류에 대한 자세한 내용을 원격으로 볼 수 없게 되어 있습니다. 그러나 로컬 서버에서 실행되는 브라우저를 사용하면 내용을 볼 수 있습니다.            <br><br>            <b>자세히:</b> 이러한 특정 오류 메시지의 자세한 내용을 원격 컴퓨터에서 보려면 현재 웹 응용 프로그램의 루트 디렉터리에 있는 &quot;web.config&quot; 구성 파일에 &lt;customErrors&gt; 태그를 만듭니다. 그런 다음 &lt;customErrors&gt; 태그의 &quot;mode&quot; 특성을 &quot;off&quot;로 설정해야 합니다.<br><br>            <table width=100% bgcolor="#ffffcc">               <tr>                  <td>                      <code><pre>&lt;!-- Web.Config 구성 파일 --&gt;&lt;configuration&gt;    &lt;system.web&gt;        &lt;customErrors mode=&quot;Off&quot;/&gt;    &lt;/system.web&gt;&lt;/configuration&gt;</pre></code>                  </td>               </tr>            </table>            <br>            <b>참고:</b> 응용 프로그램의 &lt;customErrors&gt; 구성 태그에 있는 &quot;defaultRedirect&quot; 특성을 사용자 지정 오류 페이지 URL을 가리키도록 수정하면 현재 표시된 오류 페이지가 사용자 지정 오류 페이지로 바뀝니다.<br><br>            <table width=100% bgcolor="#ffffcc">               <tr>                  <td>                      <code><pre>&lt;!-- Web.Config 구성 파일 --&gt;&lt;configuration&gt;    &lt;system.web&gt;        &lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;mycustompage.htm&quot;/&gt;    &lt;/system.web&gt;&lt;/configuration&gt;</pre></code>                  </td>               </tr>            </table>            <br>    </body></html>
...