android implements http to request access to methods to add cookie

  • 2020-10-07 18:52:15
  • OfStack

This article illustrates how android implements http to request access to add cookie. To share for your reference, the details are as follows:

1 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 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 has been helpful in Android programming.


Related articles: