ExpirationDate
Double
Options available
The expiration time of the cookie object, in units sThe session-level cookie object does not have this attribute because it expires at the end
StoreId
String
Must-Choose
ID of the Cookiestore that contains the cookie object
Among them, the Chrome.cookies.CookieStore object represents the cookie warehouse in the browser, common
The humble article uses the JMeter to test the Beijing PK10 platform Production (www.1159880099.com) QQ1159880099 with the CSRF token authentication Web API; In recent days, the project was not busy and practiced coding.With the foundation of the previous JMeter script, basically the difficulty is in two places: Get the CSRF token, the transfer of the cookie.Add dependencies First, and add the following in Pom.xml: Explanatory effect:
HttpClient: Used to create httpClient, manage get
Httpclient can be used together with persistent cookie storage that implements the cookiestore interface in any physical representation. The default cookiestore implementation is called basicclientcookie, which is a simple implementation of Java. util. arraylist. Cookies stored in the basicclientcookie object are lost when the container object is recycled by the garbage collection mechanism. If necessary,
AngularJS provides good $cookie and $cookieStore APIs to handle cookies.Both services are able to play HTML5 cookies well, and when the HTML5 API is available the browser chooses to use the API provided by HTML5 and, if not available, chooses document.cookies by default. Either way, you can choose to use phaseThe same API to work on.You can now manipulate cookies using the put, get, and remove methods, $cookieStor
Angular's cookie read/write method, angularcookie read/write
AngularJS encapsulates a separate module for cookie operations, the module name is ngCookies, if you want to use the need to first introduce angular-cookies.js in the page:
Then inject the ngCookies module into the dependent modules of our custom modules:
var app = angular.module("myApp",['ngCookies']);
The ngCookies module provides two services related to the reading and writing of cookies: $ cookies and $ cookieStroe. Regardless of
Httpclient4.x can bring its own maintenance session functionality, as long as the same httpclient is used and the connection is not closed, you can use the same session to access other services that require login verification (see the "Performing a GET Request" section in the Testlogin () method).If you need to use the httpclient pool, and you want to do a single logon session for multiple httpclient connections, you need to save the session information yourself. Because the client's session inf
(GlobalConfig). build (); Requestconfig localconfig = requestconfig.copy (GlobalConfig). Setcookiespec (cookiespecs.standard_strict). build (); HttpGet httpget = new HttpGet ("/"); Httpget.setconfig (Localconfig);3.4 Customizing Cookie PoliciesIn order to implement a custom cookie policy, you should create a custom Cookiespec interface implementation, create a Cookiespecprovider implementation class to create and initialize an instance of the custom specification , and use HttpClient to regist
Process:First, the Android side uses HttpClient to send HTTP requests, when the server creates a cookie, sends a cookie to the Android, and then saves the cookie on the Android side. Sent with an HTTP request when a cookie needs to be sent.The code is as follows: Public Static Cookiestore Cookiestore; // static, used to store cookies // omit a bunch of code New defaulthttpclient (); Httpclient.setcookiestor
)
. build ();
HttpGet httpget = new HttpGet ("/");
Httpget.setconfig (Localconfig);
3.4 Custom Cookie policy
To implement a custom cookie policy, you should create a custom Cookiespec interface implementation, create a Cookiespecprovider implementation class, and then use the implementation class to create and initialize an instance of the custom specification, and then register with HttpClient , once the custom specification is registered, it will be triggered just like the standar
Http://blog.memecodes.com/340.htmlIn the HTTP connection, there will be a cookie status, need to access the login page, you must save the cookie for authentication, and each time you send a request, the saved cookie will be brought together to achieve login access. Development, the general use of components, frameworks, platforms and other methods for rapid development, this article will describe how to use the Xutils framework to save cookies.Save cookies with Xutils
1
Http
angular must first introduce the Angular-cookies.js file. The following is a link to a version that can be opened directly in the browser: https://cdn.bootcss.com/angular-cookie/4.1.0/angular-cookie.jsThe following is the syntax for storing tokens in a angular cookie://Store Tokensangular. Module ('Theme.demos.login_page', ['ngcookies']). Controller ('Logincontroller'['$scope','$cookieStore', function ($scope, $c
Because the code and Java with Apache httpclient send post requests most of the repetition, so do not paste the entire code, only the different places posted.Cookies must be sent before sending a cookie, so at least two requests are sent, and for the first time a cookie is used, and the second time a cookie is added before the request is sentBefore sending the POST request for the first time, a reference to the Defaulthttpclient object is established, and the reference is not established above,
Httpclient simulated login implementation
The simplest way is to customize an httpclient through the obtained cookie. If you are interested, you can understand this article.
Httpclient simulated login (set cookie using js)
The Code is as follows:
H4ttpclient 4.3:
The simplest way is to customize an httpclient through the cookie. Based on the example above, the method is as follows:
The Code is as follows:
CookieStore
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.