OK, now that you haven't summarily dismissed my comment, my guess is that it is definitely your problem and explains why your code looks like incomprehensible junk.
I get the impression that cosm underwent a palace revolution about last September and, unless you are one of the gold star brigade, anything you pick up on this matter that is older than that, is just going to cause you grief.
Check the cosm site, get the kosher libraries, cosm.h and httpclient, and you will probably be fine. You will see examples in the "It Worked!" section of the cosm forum, including one of mine, and there is stuff included with the libraries.
I do hope your ethernet shield is WIZ5100 based........