zoukankan      html  css  js  c++  java
  • Android怎样在http头信息里设置參数

    在使用http请求server时经常要传递一些參数给server。如IMEI号、平台号、渠道号、client的版本等一些通用信息,像这些參数我们没有必要每次都拼在url后,我们能够统一加入到http头里。

    1.HttpClient的设置http头的參数

    	 HttpClient httpclient = new DefaultHttpClient();
    
    	 httpclient.getParams().setParameter(
    	 CoreConnectionPNames.CONNECTION_TIMEOUT, CONN_TIME_OUT);
    	 HttpGet httpget = new HttpGet(url);
    	 httpget.addHeader("version", SystemInfo.getVersionChars());
    	 httpget.addHeader("client_token", SystemInfo.getIMEI());
    	 httpget.addHeader("platform", SystemInfo.getPlatForm() + "");
    	 httpget.addHeader("channel_id", SystemInfo.getChannelId() + "");


    2.HttpURLConnection的设置http头的參数

    httpURLConnection.addRequestProperty("version",
    				SystemInfo.getVersionChars());
    		httpURLConnection.addRequestProperty("client_token",
    				SystemInfo.getIMEI());
    		httpURLConnection.addRequestProperty("platform",
    				SystemInfo.getPlatForm() + "");
    		httpURLConnection.addRequestProperty("channel_id",
    				SystemInfo.getChannelId() + "");

    	httpURLConnection.setRequestProperty("version",
    				SystemInfo.getVersionChars());
    		httpURLConnection.setRequestProperty("client_token",
    				SystemInfo.getIMEI());
    		httpURLConnection.setRequestProperty("platform",
    				SystemInfo.getPlatForm() + "");
    		httpURLConnection.setRequestProperty("channel_id",
    				SystemInfo.getChannelId() + "");


    技术交流QQ群6399844




  • 相关阅读:
    利用数组将九种颜色不重复的显示在九个盒子中
    gulp结合webpack开启多页面模式,配置如下
    parent获取子元素以及自身元素
    利用键值对来找对应值的信息
    Math.random 随机数方法
    常用linux,DOS命令——持续更新
    函数嵌套函数传递this值
    空对象模式
    状态模式(状态机)
    观察者模式
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/6753612.html
Copyright © 2011-2022 走看看