. .

st4u

ST 4U 192: Http Get in VA Smalltalk

February 10, 2012 12:20:39.339

Today's Smalltalk 4 You looks at client level HTTP (specifically, get) in VA Smalltalk. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

HTTP Get.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Today we'll take a look at doing HTTP queries in VA Smalltalk. To get started, you'll need to load the SST (server Smalltalk) packages for HTTP:

Load HTTP Support

All we'll be looking at today is the client side of HTTP, but you need to server package to get that in the image. Once you do that, take a look at class SstHttpClient:

Http Client

A quick look at the APIs makes it appear that all you need to do is create an instance and start using #get:, but it's a bit more involved than that:

Create a client and query

Here's the code:


"set up a client for http requests and execute a request"
client := (SstHttpClient forTransportScheme: 'http') startUp.


That sets up a client for usage. Notice that we needed to specify http (you could also specify https - we'll get into things like proxy servers in the future). next, you issue the request. Once you've "started" the client, you can continue to issue requests:


response := client get: 'http://www.yahoo.com'.

if you inspect the result, you'll see the full response object:

HTTP Response

To get the content, simply send #asString to that piece of the response.

Finally, when you are finished with the client, shut it down:


client shutDown.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

Enclosures:
[st4u192-iPhone.m4v ( Size: 5283289 )]

posted by James Robertson

 Share Tweet This