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:
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:
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:
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:
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:
To get the content, simply send #asString to that piece of the response.
Finally, when you are finished with the client, shut it down:
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.
[st4u192-iPhone.m4v ( Size: 5283289 )]