Android如何在http头信息里设置参数

在使用http请求server时常常要传递一些参数给server,如IMEI号、平台号、渠道号、客户端的版本号等一些通用信息,像这些参数我们没有必要每次都拼在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() + "");
时间: 2024-12-21 08:42:55

Android如何在http头信息里设置参数的相关文章

Android 如何在Java代码中手动设置控件的marginleft

1.定义LayoutParams LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);//定义一个LayoutParams 2.在LayoutParams中设置marginLeft layoutParams.setMargins(20,0,0,0);//4个参数

Android如何在java代码中设置margin

习惯了直接在xml里设置margin(距离上下左右都是10dip),如: <ImageView android:layout_margin="10dip" android:src="@drawable/image" /> 只是有些情况下,需要在java代码里来写. API中,android.view.ViewGroup.MarginLayoutParams有个方法setMargins(left, top, right, bottom).可是View本身没

PHP设置头信息,取得返回头信息

php 设置头信息,取得返回头信息 张映 发表于 2011-05-27 分类目录: php 设置请求的头信息,我们可以用header函数,可以用fsockopen,可以用curl等,本文主要讲的是用curl来设置头信息,并取得返回后的头信息. 一,请求方设置自己的头信息,header.php 查看复制打印? <?php function FormatHeader($url, $myIp = null,$xml = null) { // 解悉url $temp = parse_url($url);

Android 如何用HttpClient 以Post方式提交数据并添加http头信息

转自:http://www.linuxidc.com/Linux/2011-09/42772.htm Android 如何 post json格式的数据,并附加http头,接受返回数据,请看下面的代码: 1 private void HttpPostData() { 2 try { 3 HttpClient httpclient = new DefaultHttpClient(); 4 String uri = "http://www.yourweb.com"; 5 HttpPost

转--Android如何在java代码中设置margin

http://www.2cto.com/kf/201207/140111.html 红黑联盟: 习惯了直接在xml里设置margin(距离上下左右都是10dip),如: <ImageView android:layout_margin="10dip" android:src="@drawable/image" /> 只是有些情况下,需要在java代码里来写. API中,android.view.ViewGroup.MarginLayoutParams有个

设置请求头信息的不同方式

原文:http://blog.csdn.net/magiclr/article/details/49643277 在AngularJs中有三种方式可以设置请求头信息: 1.在http服务的在服务端发送请求时,也就是调用http()方法时,在config对象中设置请求头信息: $http.post('/somePath' , someData , { headers : {'Authorization' : authToken} }).success(function(data, status,

phpstorm设置方法头信息备注

一.目标,如下图,希望在方法上增加如下头信息备注 二.设置live template: 三.增加方法头信息备注,如下所示: * created by ${USER} at ${DATE} ${TIME} 原文地址:https://www.cnblogs.com/zhengchuzhou/p/9986159.html

HTTP头信息(转)--1

转自:http://www.cnblogs.com/9988/archive/2012/03/21/2409086.html 我用抓包软件抓了http的包,发现accept大多数有两种情况. 第一种:Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, a

android如何在textview或edittext上添加表情

先上效果图: 首先来写一个表情的GridView public class EmotionView extends LinearLayout implements OnItemClickListener { private GridView mGridView; private static final ArrayList<Integer> emotionDisplayList = new ArrayList<Integer>(); public static final Link