当前位置: 移动技术网 > IT编程>移动开发>Android > android实现http中请求访问添加cookie的方法

android实现http中请求访问添加cookie的方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

iesp-569,冲孔板厂,火爆地带价格查询

本文实例讲述了android实现http中请求访问添加cookie的方法。分享给大家供大家参考,具体如下:

第一种

hashmap<string, string> map = new hashmap<string, string>();
map.put("cookie","p1u_id=4eb591e73554db0f4d3300cb656113abfb968ef6b0ee2b5de0a35caa5217c51faa028b453576b35c");
networkconnection.setheaderlist(map);
networkconnection.connectionresult result = networkconnection.execute();

第二种是用okhttp

okhttpclient client = new okhttpclient();
string returndata=null;
com.squareup.okhttp.request request = new com.squareup.okhttp.request.builder()
  .addheader("cookie", "p1u_id=4eb591e73554db0f4d3300cb656113abfb968ef6b0ee2b5de0a35caa5217c51faa028b453576b35c")
  .url(url)
  .build();
response response = null;
try {
  response = client.newcall(request).execute();
  returndata=response.body().string();
  log.i("ss", "url is " + url + "_______retunrn data is " + returndata);
} catch (ioexception e) {
  e.printstacktrace();
}

希望本文所述对大家android程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网