Latest CookieInfo objects from HTTP response message history
infos = matlab.net.http.CookieInfo.collectFromLog( returns
for all the valid cookies found in the Set-Cookie header fields of
the response message history. Use
obtain the latest cookies from a history of messages, such as those
exchanged during a transaction involving authentication or redirection.
If a server sends multiple versions of the same cookie, then
only the most recent. This method also eliminates cookies that might
not be valid for the URI of the server, that is, whose Domain is inconsistent
with the request URI.
Eliminate message redirection by reusing cookies.
Send a message to a fictional website using redirection. Multiple messages are exchanged. To execute this code, you must provide a valid URI.
import matlab.net.http.* import matlab.net.http.field.* r = RequestMessage; [resp,~,history] = r.send('http://www.somewebsite.com'); disp(length(history))
Extract the cookies from the message history.
cookieInfos = CookieInfo.collectFromLog(history); if ~isempty(cookieInfos) cookies = [cookieInfos.Cookie]; end
Apply the cookies to the next request. Only one message is exchanged.
r = RequestMessage(,CookieField(cookies)); [resp,~,history] = r.send('http://www.somewebsite.com'); disp(length(history))