MIS 543 Online
-
Business Data Communications & Networking
Project 1: Simple HTTP Client
python web_client.py
http://localhost:8000/test.html
test.html
Note here the URL is using port 8000 on the localhost (a web server on the local machine). You can use
the simple HTTP server provided by Python to test this feature by typing the following in the command
line/terminal:
python -m http.server 8000 --bind 127.0.0.1
Then the simple HTTP server will start to serve the files in the folder where you start the server. Read
the details at
https://docs.python.org/3/library/http.server.html
.
Once you have parsed the URL, you will need to create an HTTP GET request and send it to the server.
You should include the "Host" header field with HTTP/1.1. After sending the GET request, you need to
receive the response from the server. Save the response body to the specific file.
You are encouraged to use the
socket
-
Low-level networking interface
library for connecting to the
remote server and sending/receiving data (https://docs.python.org/3/library/socket.html). If you use
socket, both the HTTP request and response are just text files (bytes) sending through the connection.
You should use "
n" for
a new line. You can also use other libraries as long as your program meets the
requirements.
There are several useful functions you may need. You may need to ge
t the server's IP address using its
domain name. The
socket.gethostbyname(hostname)
function will take a domain name, invoke the DNS
protocol for you to look up the server's IP address, and return that address as a string.
The
urlparse(URL)
function will take your URL, and parse different components of the URL. See the comments in the starter
code for details.
What to turn in
Turn in your completed
web_client.py
to D2L.
Grading
Your project will be graded by a script which will run the submitted code under a variety of conditions.
These grades will be determined automatically from the results from the script. Therefore, test your
code thoroughly and make sure they pass the following grading criteria before you submit it.
4 pts
HTML Request
The client should be able to request and download HTML files. The
downloaded file should be the same as the original file. You can use
http://www.u.arizona.edu/~weichen/MIS543/test.html
to test.
3 pts
PNG Request
The client should be able to request and download PNG (binary) files. The
downloaded file should be the same as the original file. You can use
http://www.u.arizona.edu/~weichen/MIS543/test.png
to test.
2 pts
Exception
If the server responds with any status code rather than 200 OK, web_client.py
Handling
should put the HTTP response line in the specified file. You can test with a non-
existing file, e.g.,
http://www.u.arizona.edu/~weichen/MIS543/none.html
.
2
MIS 543 Online
-
Business Data Communications & Networking
Project 1: Simple HTTP Client
1 pts
Alternative
The client should be able to handle an alternative port, e.g.,
Port
http://localhost:8000/test.html
. Use the simple HTTP server mentioned above
to test it..