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() + "");
Android如何在http头信息里设置参数的更多相关文章
- Android怎样在http头信息里设置參数
在使用http请求server时经常要传递一些參数给server.如IMEI号.平台号.渠道号.client的版本等一些通用信息,像这些參数我们没有必要每次都拼在url后,我们能够统一加入到http头 ...
- Android 如何在Java代码中手动设置控件的marginleft
1.定义LayoutParams LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.La ...
- Httphelper头信息(ContentType)默认为text/html无懈可击
Httphelper头信息(ContentType)默认为text/html无懈可击转 http://www.sufeinet.com/thread-8623-1-1.html 我发现最近有几个网友提 ...
- selenium设置chrome和phantomjs的请求头信息
selenium设置chrome和phantomjs的请求头信息 出于反爬虫也好-跳转到手机端页面也好都需要设置请求头,那么如何进行呢? 目录 一:selenium设置phantomjs请求头: ...
- 前后端分离产生的跨域问题的解决方案之--jsonp、nginx代理、设置头信息等
前言 在前后端没有分离的时候,前端开发要么是写静态页面,数据渲染后端来做,要么就是前端的页面和后端的代码刚开始的时候就合并在一起,每次后端代码更新了之后,前端也要更新一下代码,然后重启一下服务,还是比 ...
- android软件简约记账app开发day10-主页面模块--头信息的展示,和之后功能完善的目标。
android软件简约记账app开发day10-主页面模块--头信息的展示,和之后功能完善的目标. 今天来写主界面头信息的展示,也就是将第一天的写的layout中的item_main_top展示到主界 ...
- 在AngularJs中怎么设置请求头信息(headers)及不同方法的比较
在AngularJS中有三种方式可以设置请求头信息: 1.在http服务的在服务端发送请求时,也就是调用http()方法时,在config对象中设置请求头信息:事例如下: $http.post('/s ...
- Android如何在java代码中设置margin
习惯了直接在xml里设置margin(距离上下左右都是10dip),如: <ImageView android:layout_margin="10dip" android:s ...
- 转--Android如何在java代码中设置margin
======== 3 在Java代码里设置button的margin(外边距)? 1.获取按钮的LayoutParams LinearLayout.LayoutParams layoutParams ...
随机推荐
- django CBV基于类视图简单实例
URLS: from django.contrib import admin from django.urls import path from cmbd import views urlpatter ...
- requests库(爬虫)
北京理工大学嵩天老师的课程:http://www.icourse163.org/course/BIT-1001870001 官方文档:http://docs.python-requests.org/e ...
- 【ELK】之Kibana使用
GET _search { "query": { "match_all": {} } } GET _cat/indices GET elk- GET /elk- ...
- nginx http转 https
场景 项目前期使用http,后期为了安全方面的考虑,启用了https.项目架构:前端使用nginx作为多个tomcat实例的反向代理和负载均衡.实际上只需要在nginx上启用https即可,使客户端与 ...
- android AES 加密解密
import java.security.Provider; import java.security.SecureRandom; import javax.crypto.Cipher; import ...
- MySQL修改数据库、表、列、外键字符编码和排序编码
在重启Confluence应用时,突然遇见这个检查错误,查询总结需要修改Mysql数据库的所有字符编码和排序编码,报错如下: Confluence Help – This installation o ...
- 读写txt
FileStream fileStr = new FileStream("shaftCofig.txt", FileMode.OpenOrCreate); StreamReader ...
- Android Studio设置连续按两次退出APP
主要是在onKeyDown方法中进行操作,直接上代码. private long mTime; @Override public boolean onKeyDown(int keyCode, KeyE ...
- Axiso解决跨域访问(...XMLHttpRequest cannot load http://xxx.xxx No 'Access-Control-Allow-Origin'...)
直接访问如下:this.$axios.get("http://localhost:8089/yc/demo").then(res=>{ console.log(res) ...
- Calendar打印日历
package com.example.demo; import org.junit.Test; import org.junit.runner.RunWith; import org.springf ...