When accessing a website, it can show window asking for username and password authentication.How would I send user/pass information with TCPObjects?
For example, given the user name 'Aladdin' and password 'open sesame', the string 'Aladdin:open sesame' is Base64 encoded, resulting in 'QWxhZGRpbjpvcGVuIHNlc2FtZQ=='.
GET /private/index.html HTTP/1.1Host: localhostAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Though how to specifically use this information, I'm unsure.
function authConnection::onLine(%this,%line){ echo(%line);}function authConnection::onConnected(%this){ %this.send("GET /index.htm HTTP/1.1\r\n"); %this.send("Host: 10.0.0.1\r\n"); %this.send("Authorization: Basic ********\r\n"); %this.send("\r\n");}new TCPObject(authConnection);authConnection.connect("10.0.0.1:80");
function base64(%str){ %base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; %asciimap = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN" @ "OPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; %len = strLen(%str); for(%i = 0; %i < %len; %i++) { %chr = getSubStr(%str,%i,1); %ascii = strPos(%asciimap,%chr) + 32; %bin = convertBase(%ascii,"0123456789","01"); while(strLen(%bin) < 8) %bin = "0" @ %bin; %all = %all @ %bin; } %len = strLen(%all); for(%i = 0; %i < %len; %i += 6) { %pack = getSubStr(%all,%i,6); while(strLen(%pack) < 6) %pack = %pack @ "0"; %dec = convertBase(%pack,"01","0123456789"); %new = %new @ getSubStr(%base64map,%dec,1); } while(strLen(%new) % 4 > 0) %new = %new @ "="; return %new;}function convertBase(%val,%atype,%btype){ %vlen = strLen(%val); %alen = strLen(%atype); %blen = strLen(%btype); for(%i = 0; %i < %vlen; %i++) %sum += striPos(%atype,getSubStr(%val,%i,1)) * mPow(%alen,%vlen - %i - 1); while(1) { %rem = %sum % %blen; %new = getSubStr(%btype,%rem,1) @ %new; %sum = mFloor(%sum / %blen); if(!%sum) break; } return %new;}