데이터 수신요청 쪽 ----------------------------------------------------
ArrayList<String> param = new ArrayList<String>();
param.add("url=" + MusicGlobalsClass.HTTP_HOST + "/Login.php");
String url = MusicGlobalsClass.HTTP_HOST + "/Login.php";
String parm = "mode=login";
parm += "&";
parm += "id=" + id;
parm += "&";
parm += "pw=" + pw;
HttpResponse result = null;
try {
result = new NetworkClass().execute(url, parm).get();
processEntity(result);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
private void processEntity(HttpResponse rtnResult)
{
HttpEntity entity = rtnResult.getEntity();
BufferedReader br;
String line, result = "";
try
{
br = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));
while((line = br.readLine()) != null)
{
result += line;
}
Log.i(MusicGlobalsClass.TAG, " 결과 == " + result);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
데이터 AsyncTask 처리 ----------------------------------------------------
NetworkClass.java
public class NetworkClass extends AsyncTask<String, Void, HttpResponse>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected HttpResponse doInBackground(String... param)
{
String httpHost = param[0];
String[] pm = param[1].split("&");
List postParam = new ArrayList();
UrlEncodedFormEntity entity = null;
HttpResponse response = null;
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
HttpPost httpPost = new HttpPost(httpHost);
for(int i = 0; i < pm.length; i++)
{
String[] newPm = pm[i].split("=");
postParam.add(new BasicNameValuePair(newPm[0], newPm[1]));
}
try
{
entity = new UrlEncodedFormEntity(postParam, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
httpPost.setEntity(entity);
try
{
response = client.execute(httpPost);
}
catch(ClientProtocolException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
return response;
}
@Override
protected void onPostExecute(HttpResponse result) {
super.onPostExecute(result);
}
}