with the help of the comments I was able to achieve the big part of what I was looking for.
first problem is to get the cookie info in MATLAB. versions earlier than 2016b are probably not able to do it, so I had to use urlread2 for it: [output,extras] = urlread2('http://www.example.com/','GET');
cookie = extras.firstHeaders.Set_Cookie;
now that we have the cookie, let's add it to the weboptions like this:
opts = weboptions('KeyName','Cookie','KeyValue',cookie);
and now simply every time that you use webread or webwrite , attach the opts to it:
response = webread('http://www.example.com/',opts);
But using this method, it is very easy to do XSS attacks on websites that use HTTPOnly cookies for session management! unlike all the web browsers, matlab allows you to edit or create HTTPOnly cookies! more info here
Best Answer