RSS feed
<< Why use a router at home | Home | Simple email service request >>

Simple web service request

Yesterday I briefly explained how programs listened on ports. Some of these programs, like web servers, use very simple to understand commands. When you use a web browser to communicate with a web server, the browser sends the commands for you. The commands are actually so simple that you can send them yourself and avoid using the web browser entirely. When you point your browser at http://www.google.com/ your browser contacts the web server and requests the default page also known as /. If you typed something in the search bar and hit search you could request another web page. If your address bar read http://www.google.com/search?hl=en&q=TEST&btnG=Google+Search then it would indicate it was requesting /search?hl=en&q=TEST&btnG=Google+Search page.

You could request the default page yourself using a program called telnet. Simply open a command prompt and type telnet www.google.com 80 and hit enter. The next command will be invisible so make sure you're hitting the right keys. When the screen clears, type GET / and hit enter. The web server should respond with a bunch of HTML.

These are the basics of speaking in HTTP. Many applications are being either retrofitted or designed from the onset to support HTTP requests. One of the more popular examples of using HTTP communication is the stock quote. Here is a simple example of making a request to get the value of Google stock. If you look closely you can see that it's valued at 638.25 today.

GET /stockquote.asmx/GetQuote?symbol=GOOG
HTTP/1.1 200 OK
Date: Fri, 11 Jan 2008 21:43:45 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 728

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://www.webserviceX.NET/">&lt;StockQuotes&gt;&lt;Stock&gt;&lt;
Symbol&gt;GOOG&lt;/Symbol&gt;&lt;Last&gt;638.25&lt;/Last&gt;&lt;Date&gt;1/11/200
8&lt;/Date&gt;&lt;Time&gt;4:00pm&lt;/Time&gt;&lt;Change&gt;-8.48&lt;/Change&gt;&
lt;Open&gt;642.70&lt;/Open&gt;&lt;High&gt;649.47&lt;/High&gt;&lt;Low&gt;630.11&l
t;/Low&gt;&lt;Volume&gt;4973601&lt;/Volume&gt;&lt;MktCap&gt;199.7B&lt;/MktCap&gt
;&lt;PreviousClose&gt;646.73&lt;/PreviousClose&gt;&lt;PercentageChange&gt;-1.31%
&lt;/PercentageChange&gt;&lt;AnnRange&gt;437.00 - 747.24&lt;/AnnRange&gt;&lt;Ear
ns&gt;12.783&lt;/Earns&gt;&lt;P-E&gt;50.59&lt;/P-E&gt;&lt;Name&gt;GOOGLE&lt;/Nam
e&gt;&lt;/Stock&gt;&lt;/StockQuotes&gt;&lt;/string>

This is a shell script (UNIX) to run the commands automatically.

{ echo "GET /stockquote.asmx/GetQuote?symbol=GOOG{ENTER}" ; sleep 3 ; } | telnet www.webservicex.net 80

This is a vbs script (WINDOWS) to run the commands automatically.

dim objShell
Set objShell = CreateObject("wscript.shell")
objShell.Run "telnet www.webservicex.net 80"
WScript.Sleep 3000
objShell.SendKeys "GET /stockquote.asmx/GetQuote?symbol=GOOG{ENTER}"

Update: I've updated the results so the quote values may not be the same as they were on the day this post was written.




Add a comment Send a TrackBack
Home