Android implements the method of requesting access to add cookies in HTTP _android

Source: Internet
Author: User

The example in this article describes the way that the Android implementation HTTP requests access to add cookies. Share to everyone for your reference, specific as follows:

First Kind

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

The second is the use of 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 ();
}

I hope this article will help you with the Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.