package com.example.httppostex;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class MainActivity extends Activity
{
TextView textView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.text_view);
new JsonLoadingTask().execute();
}
public String JsonTest()
{
try
{
HttpClient client = new DefaultHttpClient();
String postURL = "http://";
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("HP", "010"));
params.add(new BasicNameValuePair("CC", "KR"));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params,HTTP.UTF_8);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if (resEntity != null)
{
Log.i("RESPONSE", EntityUtils.toString(resEntity));
}
}
catch (Exception e)
{
e.printStackTrace();
}
return toString();
}
private class JsonLoadingTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... strs) {
return JsonTest();
} // doInBackground : 백그라운드 작업을 진행한다.
@Override
protected void onPostExecute(String result) {
textView.setText(result);
} // onPostExecute : 백그라운드 작업이 끝난 후 UI 작업을 진행한다.
} // JsonLoadingTask
}
이후 출력시 원하는 데이터값이 출력이 안되고 팩키지 이름과 이상한 값이 출력이 됩니다.
출력부분을 잘못 작성한건지 궁금해서 질문 드립니다.