android httppost

编辑器加载中...

/**命令,说明是哪一种查询**/
public static final String KEY_COMMAND="Command";
/**所有数据**/
public static final int VALUE_COMMAND_ALL=0;
/**附近**/
public static final int VALUE_COMMAND_NEAR=1;
/**搜索**/
public static final int VALUE_COMMAND_SEARCH=2;
/**推荐**/
public static final int VALUE_COMMAND_RECOMMEND=3;
/**最新**/
public static final int VALUE_COMMAND_NEWEST=4;
/**热门**/
public static final int VALUE_COMMAND_TOP=5;
/**排行榜**/
public static final int VALUE_COMMAND_RANKING=6;

/****参数--距离--在查找附近时有数据*******/
public static final String KEY_DISTANCE="Distance";
/****参数--坐标--在查找附近时有数据*******/
public static final String KEY_GPS="GPS";

/****参数--过滤--地区--***/
public static final String KEY_FILTER_AREA="FilterArea";
/****参数--过滤--频道**********/
public static final String KEY_FILTER_CHANNEL="FilterChannel";

/****参数--排序--***/
public static final String KEY_SORT="Sort";

/****搜索条件-***/
public static final String KEY_SEARCH_CONDITION="Condition";
/**POST数据结构**/
public static class PostData
{
public int command=0;
public int distance=5000;
public String gps="";
public int filterArea=0;
public int filterChannel=0;
public int sort=-1;
public String condition="";
private static final String POST_URL="http://192.168.11.21/test.php";
private final String DEBUG_TAG = "GoWinHttp";
public String getDataFormHttp()
{
String resultStr="";
HttpClient httpclient = new DefaultHttpClient();
//参数列表
List<NameValuePair> nameValuePairs =new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair(KEY_COMMAND,Integer.toString(command)));
nameValuePairs.add(new BasicNameValuePair(KEY_DISTANCE,Integer.toString(distance)));
nameValuePairs.add(new BasicNameValuePair(KEY_GPS,gps));
nameValuePairs.add(new BasicNameValuePair(KEY_FILTER_AREA,Integer.toString(filterArea)));
nameValuePairs.add(new BasicNameValuePair(KEY_FILTER_CHANNEL,Integer.toString(filterChannel)));
nameValuePairs.add(new BasicNameValuePair(KEY_SORT,Integer.toString(sort)));
nameValuePairs.add(new BasicNameValuePair(KEY_SEARCH_CONDITION,condition));
HttpPost httppost = new HttpPost(POST_URL);
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response;
response=httpclient.execute(httppost);
resultStr=EntityUtils.toString(response.getEntity());
} catch (UnsupportedEncodingException e) {
Log.d(DEBUG_TAG, "UnsupportedEncodingException");
e.printStackTrace();
} catch (ClientProtocolException e) {
Log.d(DEBUG_TAG, "ClientProtocolException");
e.printStackTrace();
} catch (IOException e) {
Log.d(DEBUG_TAG, "IOException");
e.printStackTrace();
}
return resultStr;

}
}

转载于:https://www.cnblogs.com/meieiem/archive/2011/09/27/2192754.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值