Archive for May, 2007

31
May

Post Variables. Where do they go?

So the problem is that GET variables are sent through the header, which means there is a size limitation. This poses a problem when the length of the variables you are trying to send in is around 8000 characters long. So you have to use POST to make it work correctly. And if you need to also authenticate while sending post variables you will also have to worry about sending everything through a socket connection and writing your own headers once again. They should look like this:

POST /apis/script.php HTTP/1.0
Host: jordan.dev.com
Authorization: Basic MTE6Y2FybHNleBLAHWxscw==
Content-type: application/x-www-form-urlencoded
Content-Length: 8895

var1=something&var2=somethingelse

The Content-type and Content-Length lines are the important headers. While the var1=something&var2=somethingelse placement is also important. It is in the body of the request, not in the header.

31
May

HTTP Headers can be fun!

So here is the dilemma. You want to authenticate against standard http authentication and you want to use flash and actionscript 3.0 to do it. So you go into the help and find out that this simple thing just is not possible. So you google around for about an hour and find out that one person seems to have written something that will get you moving in the direction you need to be going.

The simple explanation of how you get through http authentication using flash is that you open a socket connection and write the headers yourself. Something like this.


__socket = new Socket();
__headers = new Array();

var bArray:ByteArray = new ByteArray();
bArray.writeUTFBytes(username + “:” + password);
__auth64 = Base64.Encode(bArray);

//by default we are adding the authentication header
addHeader(”Authorization”,”Basic ” + __auth64);

__socket.connect(__httpServer, __httpPort);

So your headers will look something like this before you send them in using __socket.writeUTFBytes(header_var);

POST /apis/script.php HTTP/1.0
Host: jordan.dev.com
Authorization: Basic MTE6Y2FybHNleSMTYWxscw==

The (Authorization: Basic base64encodedstring) is the important part here. This is the part of the header that will allow the authorization to take place without presenting the ugly standard login box that would normally appear.

Web-Sniffer was so helpful in figuring out what the headers needed to look like. It shows the request and response headers in http 1.0 and 1.1.

Overall this experience was awesome, and there are just tons of things that can be done using headers.