• 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;

    }
    }
  • 相关阅读:
    模板template用法
    关联式容器MAP的用法----类似与python中的dict
    迭代器iterator
    c++中的vertor
    Git操作(git reset & get revert)
    代码度量标准
    __attribute__关键字
    Centos7.2部署.Net Core2.0 WebApi
    通过nginx 访问 centos 7 服务器上的.Net Core
    ASP.NET Core部署到CentOS7,使用Nginx代理
  • 原文地址:https://www.cnblogs.com/meieiem/p/2192754.html
Copyright © 2020-2023  润新知