当前位置: 编程技术>移动开发
本页文章导读:
▪HttpURLConnection重定向,获取及设立cookie HttpURLConnection重定向,获取及设置cookieHttpURLConnection获取重定向地址和cookie的代码如下:public void first() throws Exception{
Map<String, String> paramsHashMap = new HashMap<String, String>();
paramsHashMap.put(.........
▪ 手逛是越来越牛逼了-混沌与秩序Online 手游是越来越牛逼了--混沌与秩序Online下了个IOS版 混沌与秩序Online 体验了下,
操作非常流畅,体验非常好,除了手机屏幕的限制,其他感觉和PC基本已无差别
随着手机配置越来越高,3D手游.........
▪ KDE 等离子体媒体中心首次亮相 KDE 等离子媒体中心首次亮相
KDE项目的开发者们发布了等离子媒体中心(PMC)的第一个版本。“等离子媒体中心”为桌面和任何能够运行KDE的设备而设计。据开发者透露,PMC能用于看录像,听.........
[1]HttpURLConnection重定向,获取及设立cookie
来源: 互联网 发布时间: 2014-02-18
HttpURLConnection重定向,获取及设置cookie
HttpURLConnection获取重定向地址和cookie的代码如下:
public void first() throws Exception{
Map<String, String> paramsHashMap = new HashMap<String, String>();
paramsHashMap.put("IF_NO", "IF0002");
paramsHashMap.put("UID", "12345");
firstRequest(API_HTTP, paramsHashMap, "UTF-8");
}
private void firstRequest(String path, Map<String, String> params, String encoding) throws Exception{
StringBuilder sb = new StringBuilder();
if(params!=null && !params.isEmpty()){
for(Map.Entry<String, String> entry : params.entrySet()){
sb.append(entry.getKey()).append('=');
sb.append(URLEncoder.encode(entry.getValue(), encoding));
sb.append('&');
}
sb.deleteCharAt(sb.length() - 1);
}
byte[] entity = sb.toString().getBytes();
HttpURLConnection conn = (HttpURLConnection) new URL(/blog_article/path/index.html).openConnection();
conn.setInstanceFollowRedirects(true);
conn.setConnectTimeout(5000);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(entity.length));
OutputStream outStream = conn.getOutputStream();
outStream.write(entity);
//获取重定向地址
redictURL= conn.getHeaderField( "Location" );
System.out.println("第一次请求重定向地址 location="+redictURL);
System.out.println("第一次请求 conn.getResponseCode()="+conn.getResponseCode());
//获取cookie
Map<String,List<String>> map=conn.getHeaderFields();
Set<String> set=map.keySet();
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
String key = (String) iterator.next();
if (key.equals("Set-Cookie")) {
System.out.println("key=" + key+",开始获取cookie");
List<String> list = map.get(key);
StringBuilder builder = new StringBuilder();
for (String str : list) {
builder.append(str).toString();
}
firstCookie=builder.toString();
System.out.println("第一次得到的cookie="+firstCookie);
}
}
}
HttpURLConnection在请求头中设置cookie的代码如下:
conn.setRequestMethod("POST");
conn.setRequestProperty("Cookie", firstCookie);
[2] 手逛是越来越牛逼了-混沌与秩序Online
来源: 互联网 发布时间: 2014-02-18
手游是越来越牛逼了--混沌与秩序Online
下了个IOS版 混沌与秩序Online 体验了下,
操作非常流畅,体验非常好,除了手机屏幕的限制,其他感觉和PC基本已无差别
随着手机配置越来越高,3D手游肯定会有更大的发展!
[3] KDE 等离子体媒体中心首次亮相
来源: 互联网 发布时间: 2014-02-18
KDE 等离子媒体中心首次亮相
KDE项目的开发者们发布了等离子媒体中心(PMC)的第一个版本。“等离子媒体中心”为桌面和任何能够运行KDE的设备而设计。据开发者透露,PMC能用于看录像,听音乐和浏览照片集,它旨在提供一个可用于传统PC,平板,上网本和TV的用户界面。
PMC 1.0的功能包括浏览本地媒体文件,浏览Flickr和谷歌Picasa等来源于网上的照片,根据内容创建播放列表,可按序或随机播放。PMC集成了KDE桌面搜索,来帮助用户访问系统上的所有可用资源。开发者同时指出,PMC有一个插件基础设施,可用于开发自定义插件。
最新技术文章: