Spork Code

Code. Randomness. Sporks.

Archive for June 2009

HTTP Posts in Apache’s new HttpClient 4.0 (with Lighttpd)

leave a comment »

Apache is developing a new HTTP library which is not based on the current Commons libraries. The documentation on the new libraries can be found here. I came across the new library while developing for Google’s Android platform, which uses HttpClient 4.0 for its HTTP protocol handling. The new libraries work well, but I spent a considerable amount of time trying to figure out why it was that I couldn’t get my server to accept the information I had POSTed to it. I finally discovered that the issue was with Lighttpd. Lighttpd was the web server used for the service I was POSTing to. It turns out that Lighttpd has had a long-standing issue with the Expect 100-Continue header. Fortunately, this issue has been resolved in Lighttpd 1.5, but for earlier versions it had never been patched. I had to turn, instead to a rather obscure function which disabled that header. Here is the code:

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);

//THIS IS THE LINE WE CARE ABOUT TO FIX LIHTTPD POSTS
HttpProtocolParams.setUseExpectContinue(params, false);
try {
   StringEntity se = new StringEntity( /* post params went here */ );
   post.setEntity(se);
} catch (UnsupportedEncodingException e1) {
   e1.printStackTrace();
}
try {
   HttpResponse resp =  client.execute(post);
} catch (ClientProtocolException e) {
   e.printStackTrace();
} catch (IOException e) {
   e.printStackTrace();
}

Written by John Gunderman

June 30, 2009 at 9:50 pm

Posted in Uncategorized

Tagged with , , ,

Write Yourself a Scheme in 48 Hours

leave a comment »

I’ve always had issues with finishing projects I start, but I think I’ve found something that I will be able to finish. It is a handy little Wikibook called Write Yourself a Scheme in 48 Hours. Now I tend to be skeptical of any book that purports to teach a topic so many days, or so many hours. However, WYaS is not quite of the same variety as those boastful primers. WYaS is a book with a dual purpose. As the title states, it teaches the reader how to write the majority of a real Scheme interpreter. The language it is presented in is Haskell. According to the author of the book. the reader should end up learning both Haskell and Scheme. Personally, I am inclined to believe him, because I’ve read through the first chapter or so and have been suitably impressed. Hopefully I’ll be able to keep it going and actually finish a programming book for once. If you are even remotely interested in either of these languages or if you simply want a good book to read, I would definitely suggest reading through WYaS and seeing how you like it. I’ll keep you all updated if I come across anything interesting while reading it.

Written by John Gunderman

June 30, 2009 at 4:46 am

Posted in Uncategorized

Tagged with , ,