import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
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.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import android.util.Log;
public class HttpConn {
private HttpClient HC_httpclient = new DefaultHttpClient();
private String data_byte = null;
private String HTTP_URI = http://주소;
private int datatype = 0;
public HttpConn(byte[] data) {
datatype = 0;// 바이트
this.data_byte = new String(data);
Log.w("-->", "DATA_byte = "+new String(data));
Connection();
}
public HttpConn(String data) {
datatype = 1;//스트링
this.data_byte = data;
Log.w("-->", "DATA_String = "+data);
Connection();
}
public void Connection(){
HttpEntity httpbody = new ByteArrayEntity(data_byte);
HttpResponse httprespon = null ;
HttpParams params = new BasicHttpParams();
HttpPost methos = new HttpPost(HTTP_URI);
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("test", new String(data_byte)));
try {
methos.setEntity(new UrlEncodedFormEntity(pairs));
} catch (UnsupportedEncodingException e1) {
Log.w("-->", "UnsupportedEncodingException");
e1.printStackTrace();
}
methos.setParams(params);
try {
httprespon = HC_httpclient.execute(methos);
Log.i("-->", "GET STATUS LINE"+httprespon.getStatusLine());
} catch (ClientProtocolException e) {
Log.w("-->", "ClientProtocolException");
e.printStackTrace();
} catch (IOException e) {
Log.w("-->", "IOException");
e.printStackTrace();
}
httpbody = httprespon.getEntity();
int i = 1;
if(httpbody != null){
i++;
try {
Log.w("-->","==="+EntityUtils.toString(httpbody));
} catch (ParseException e) {
Log.w("-->", "2ClientProtocolException");
e.printStackTrace();
} catch (IOException e) {
Log.w("-->", "2IOException");
e.printStackTrace();
}
}
}
}