Main Content

Manually Redirect HTTP Messages

You can use cookies to manually handle redirects. This example uses websites named http://www.somewebsite1.com and http://www.somewebsite2.com.

import matlab.net.http.*
import matlab.net.http.field.*
r = RequestMessage;
[resp,~,history] = r.send('http://www.somewebsite1.com');
cookieInfos = CookieInfo.collectFromLog(history);
if ~isempty(cookieInfos)
    cookies = [cookieInfos.Cookie];
end
r2 = RequestMessage([],CookieField(cookies));
% This is the new location for redirection
[resp,~,history] = r.send('http://www.somewebsite2.com');