Android带Cookie的Http请求
来源:互联网 发布:优衣库淘宝假货 编辑:程序博客网 时间:2024/05/16 17:30
前段时间做项目时,通过http请求为了让服务端识别请求的客服端是唯一的,要求在http请求的头部添加Cookie,并以mac地址作为唯一标识
添加Cookie的Http请求,这里以GET请求为例
DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); //在http请求头部添加Cookie标识 httpGet.setHeader("Cookie", "MobileID000001="+ToolUtil.getGateWay(MovieBarApplication.getContext())); HttpResponse httpResponse; try { httpResponse = httpClient.execute(httpGet); InputStream is = httpResponse.getEntity().getContent(); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(is, "GBK")); String result = ""; String line = ""; while (null != (line = bufferedReader.readLine())) { result += line; } return result; } catch (ClientProtocolException e) { e.printStackTrace(); Log.i("Http Exception", "MalformedURLException: " + e.getMessage()); return null; } catch (IOException e) { e.printStackTrace(); Log.i("Http Exception", "IOException: " + e.getMessage()); return null; }
其中的ToolUtil.getGateWay(MovieBarApplication.getContext())是为了获取mac地址
/** * 获取默认网关 * * @param context * @return */ public static String getGateWay(Context context) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); return info.getMacAddress(); }
0 0
- Android带Cookie的Http请求
- Http请求带cookie
- Postman发送带cookie的http请求
- Android ImageLoader获取Http请求需带Cookie图片
- Java模拟HTTP请求,带cookie
- java中http请求带cookie
- android 中设置http请求头headers的Cookie
- 【HTTP header】【Access-Control-Allow-Credentials】跨域Ajax请求时是否带Cookie的设置
- Android http请求类添加Cookie
- android http请求 史上安卓功能最全的http请求框架(带缓存)
- Siege: 发送带Cookie的请求
- Scrapy: 发送带Cookie的请求
- 跨域请求带cookie的解决方案
- postman 发送带cookie的请求
- Scrapy: 发送带Cookie的请求
- 自带cookie的httpClient请求
- android - Volley框架请求获取Cookie和带Cookie请求链接和带参数Params
- iOS 请求带cookie
- Android项目及编码规则
- scala 多线程actor
- react-router2.0 web 使用
- Java中只有按值传递,没有按引用传递!
- 发送邮件网页样式乱了。
- Android带Cookie的Http请求
- 饿了么移动APP的架构演进
- Hbase rowkey 热点问题
- java中8种基本类型及运行转换
- MyEclipse使用总结——MyEclipse10安装SVN插件
- 利用JS实现的根据经纬度计算地球上两点之间的距离
- android的服务分类-andrioid学习之旅(94)
- Python3.4简单爬虫实现之抓取糗事百科段子
- android 仿新浪微博转发 评论悬浮框的功能