전체 소스는 아래와 같습니다.
그런데 도대체 왜..
execute 할때 IOException이 발생하는지 모르겠습니다 ㅠ-ㅠ
제가 뭘 잘못 작성한것일까요?
도움 부탁드립니다.
감사합니다!
public class PostHttp {
// Tag is for print log
private static String TAG = "PostHttp";
public PostHttp() {
super();
// TODO Auto-generated constructor stub
}
// paramList is for Expandability
public String postHttp(String url, ArrayList<NameValuePair> paramsList) {
StringBuffer builder = new StringBuffer();
HttpClient mHttpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
HttpResponse response;
HttpParams params = mHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, 15000);
HttpConnectionParams.setSoTimeout(params, 15000);
ConnManagerParams.setTimeout(params, 15000);
try {
HttpEntity entity = null;
entity = new UrlEncodedFormEntity(paramsList);
post.addHeader(entity.getContentType());
post.setEntity(entity);
response = mHttpClient.execute(post);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
// Connection success
if (statusCode == 200) {
HttpEntity entityMain = response.getEntity();
InputStream content = entityMain.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
}
// Connection fail
else {
Log.d(TAG,"PostHttp fail : "+ statusCode);
}
} catch (ClientProtocolException e) {
Log.v("SmartDialerPostHttp ClientProtocolException Error1",e.getMessage());
} catch (UnsupportedEncodingException e) {
Log.v("SmartDialerPostHttp UnsupportedEncodingException Error2",e.getMessage());
} catch (IOException e) {
Log.v("SmartDialerPostHttp IOException Error3",e.getMessage());
} catch (Exception e) {
Log.v("SmartDialerPostHttp Exception Error4",e.getMessage());
}
Log.d(TAG,builder.toString());
return builder.toString();
}
}