>package com.huayang.xiangwap.service.MobileApiManager;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.protocol.HTTP;
import org.apache.http.HttpResponse;
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.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
public class BaseTest
{
public static final String SERVER_URL ="http://localhost:8080/";
public String access(String url, String postData) {
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
HttpParams params = new BasicHttpParams();
params.setParameter("charset", HTTP.UTF_8);
httppost.setParams(params);
httppost.addHeader("charset", "utf-8");
List<BasicNameValuePair> kvps = new ArrayList<BasicNameValuePair>();
kvps.add(new BasicNameValuePair("key", postData ));
httppost.setEntity(new UrlEncodedFormEntity(kvps,HTTP.UTF_8));
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode() == 200) {
String content = EntityUtils.toString(response.getEntity(),
"utf-8");
return content;
}
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
}