Book Image

Learning Python Network Programming

By : Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington
Book Image

Learning Python Network Programming

By: Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington

Overview of this book

Table of Contents (17 chapters)
Learning Python Network Programming
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

HTTP methods


So far, we've been using requests for asking servers to send web resources to us, but HTTP provides more actions that we can perform. The GET in our request lines is an HTTP method, and there are several methods, such as HEAD, POST, OPTION, PUT, DELETE, TRACE, CONNECT, and PATCH.

We'll be looking at several of these in some detail in the next chapter, but there are two methods, we're going to take a quick look at now.

The HEAD method

The HEAD method is the same as the GET method. The only difference is that the server will never include a body in the response, even if there is a valid resource at the requested URL. The HEAD method is used for checking if a resource exists or if it has changed. Note that some servers don't implement this method, but when they do, it can prove to be a huge bandwidth saver.

We use alternative methods with urllib by supplying the method name to a Request object when we create it:

>>> req = Request('http://www.google.com', method='HEAD')
&gt...