Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


December 2000

The Command-line HTTP Client Tool

RSS
Subscribe to Windows Web Solutions | See More Resource Kit Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

The Windows 2000 Resource Kit

If you need to access a Web site from the command line or a batch file, the Command-line HTTP Client tool (httpcmd.exe) can help. This Microsoft Windows 2000 Resource Kit utility reads its input commands from simple text files, many of which are generic so that you can use them with several Web sites.

Occasionally, you might require a tool that can access a Web site or application from the command line. For example, you might want to access a site from a batch file or test to see whether a site is running. You might also need to copy the HTML content from a Web page and save it to disk. If you perform tasks such as these repeatedly, consider httpcmd.exe.

Creating and Modifying Input Files
Before you can use httpcmd.exe, you need to create an input (.req) file. Input files contain the HTTP commands you use to access a Web site. You must specify the Web site or server address on the command line.

You can create simple or complex input files. For example, I copied the contents of the default.req file

GET /default.htm HTTP/1.0

(which is installed with the resource kit) to getdefault.req. To use this input file with the HTTP command, I opened a command prompt and issued the command

httpcmd www.32x.com getdefault.req

This command executes the HTTP command and accesses default.htm from my Web site—http://www.32x.com. I could access default.htm from any other Web site by reissuing the command with a new Web site address or server.

After the command executes, it displays the returned HTML or HTTP stream to the command prompt display (STDOUT). To save this output, use the Redirect option with the command

httpcmd www.32x.com getdefault.req  > 32xresults.htm

This command sends the output to the 32xresults.htm file. If you open 32xresults.htm in a browser, it displays the default.htm page from the Web site. In this way, you can use the Command-line HTTP Client tool to retrieve a Web page and save it to disk.

The syntax of the HTTP command includes several options, as Table 1 shows. For example, use the input file

//
//  Tests If-Modified-Since headers

//
GET /default.htm HTTP/1.0
If-Modified-Since: Sun, 17 Sep 2000  08:00:00 GMT

to retrieve a page only if it's been modified after a given date. When you execute the HTTP command with this file, a page will appear only if it's been modified after Sunday, September 17, 2000, at 8:00 a.m. Greenwich Mean Time (GMT). If you use this command against http://www.32x.com, you'll receive the display that Figure 1, page 16, shows. In the first line, error 304 Not modified shows that no one has modified the page since the request date. The second line shows the type of server the site uses. The third line shows the date and time of the request. The fourth line shows the ETag, which is an HTTP header tag, and the fifth line shows the content length as 0. The content length is 0 because the file wasn't modified between September 17, 2000, and the request date in the input file.

Next, change the input file contents to

GET /default.htm HTTP/1.0
If-Modified-Since: Sun, 4 June 2000  08:00:00 GMT

and save the input file to a new file. When you run the command with the new input file, you receive the display that Figure 2 shows, followed by the HTML content. The new lines in the output indicate that the request was successful. Content-Type is now text/html, the Accept-Ranges setting shows bytes, and Content-Length now shows the length of the HTML content returned.

The folder in which you install the resource kit (by default, C:\program files\resource kit) contains several sample .req files. To better understand what you can do with the HTTP command, run these .req files against a familiar Web site, such as http://www.microsoft.com. Then, you can change entries, such as the file date, in the input file and see the results. Some of the sample .req files require input or executable files and won't work unless you customize them for your files. Most of the sample .req files require tweaking to be useful.

Next Month
You can use the Command-line HTTP Client tool for many tasks, such as automating data retrieval from a site or service or testing services. You can also use the command in a batch file to test a site under development. Copy the sample .req files to a new folder, and experiment with them. Make changes to the files and test them, but be careful of syntax when you make your changes. For example, checking for a file-modified date works only if you format your date correctly (see ifmod.req for examples of date requests).

Next month, I'll examine the HTTP Monitoring tool. With that utility, you can monitor Web sites and report the results to a file or the event log.

End of Article



Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
No Jobs, No Excitement at Apple's Last Macworld Keynote

Apple CEO Steve Jobs made the right move in skipping out on his company's last appearance at Macworld: In a Tuesday keynote address at the conference, Apple had no interesting new products to sell, opting instead to spend mind-numbing amounts of time on ...

Where is Microsoft NetMeeting in Windows XP?

...

The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...


Related Events Delivering Reliable and Effective Web-Based Applications

Making Web Application Perform Better: What to Watch, How to Watch It, and How to Fix It

Check out our list of Free Email Newsletters!

IIS and Web Administration eBooks Keeping Your Business Safe from Attack: Monitoring and Managing Your Network Security

Related IIS and Web Administration Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2009 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing