HttpURLConnection 로 인터넷 연결해서 결과값 받는데 중간에 짤립니다.
내용이 길어서 그런거 같긴한데, 뭘 설정해야 끝까지 받을 수 있을까요..?
try
{
URL url = new URL (page);
HttpURLConnection conn = (HttpURLConnection) url.openConnection ();
if (method.compareTo (HTTP_METHOD_GET) != 0)
{
conn.setDoOutput (true);
}
conn.setRequestMethod (method);
if (headers != null)
{
String headerKey[] = headers.getNameArray ();
for (int i = 0; i < headerKey.length; i++)
{
String values = headers.getValue (headerKey[i]);
conn.setRequestProperty (headerKey[i], values);
}
}
else
{
conn.setRequestProperty (CONTENT_TYPE, APPLICATION_JSON);
}
if (body != null || (filePath != null && !filePath.isEmpty ()))
{
OutputStream os = conn.getOutputStream ();
if (body != null)
{
os.write (body.getBytes ());
}
os.flush ();
os.close ();
}
int responseCode = conn.getResponseCode ();
Log.i (TAG, "responseCode = " + responseCode);
StringBuilder result = new StringBuilder ();
//if (responseCode == 200)
{
InputStreamReader ir = new InputStreamReader (conn.getInputStream ());
BufferedReader br = new BufferedReader (ir);
String output;
while ( (output = br.readLine ()) != null)
{
Log.i (TAG, "output = " + output);
result.append (output);
}
//conn.disconnect ();
String response = result.toString ();
return response;
}
} catch (Exception e)
{
StackTraceElement ste= e.getStackTrace ()[1];
Log.i (TAG, "line : " + ste.getLineNumber () +" // " + e.toString ());
}