Showing posts with label http. Show all posts
Showing posts with label http. Show all posts

Sunday, January 11, 2009

MATLAB can get binary data and set Cookies!!!

After an overnight hopeless wandering around with this mad quest in mind i finally managed to read binary data correctly via http connection AND get Cookie at the same time!!! Moreover i can post some data with Cookie via http as well.

Please, if you don't care for Cookie - just DO use urlread!!! I DO mean it!

The only working way was to use Ice(Java) functions in Matlab, which are NOT documented in any way. Therefore one needs to experiment a lot with them!

So if you are not scared yet, here we go:

To read binary data use:

uint8( DataInputStream.read() )


To get cookie use:

CookieString = char(HttpURLConnection.getCookieManager().elements.nextElement.Cookie.toString)

or the following might also work

CookieString = char(HttpURLConnection.getCookieManager().getHeaderField('Set-Cookie') )


To set cookie use:

HttpURLConnection.setRequestProperty('Cookie', CookieString )



Since i am by no means an expert neither in Java nor in Matlab i might have overlooked something. Please do let me know if you know a better way.

ps: of course you start as follows:

URL = java.net.URL('http://example.url');
HttpURLConnection = URL.openConnection();