Created
March 27, 2014 20:22
-
-
Save ltddev/9817669 to your computer and use it in GitHub Desktop.
HttpServletInvocationRequests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
HttpServetInvocationRequests.py | |
This script aims to demonstrate the same servlet invocation using a basic | |
REST architecture but instead of using the urllib2 which is part of the | |
standard Python library it uses Requests (which Pythonista supports) | |
library which is intended to be far less verbose and a much simpler api. | |
The target servlet represents the entry point of any sevice or extension | |
of the web server. in this simple use case it simply prepares a Java | |
Date object that outputs the current date-time string which is simply | |
the toString() method of the Date instance server-side. | |
The expected text value of the Response object intance is simply the | |
following form: | |
Trying to open url http://192.168.0.11:9080/HelloWorldWeb/HelloWorldServlet | |
The current date and time is: <b>Thu Mar 27 13:24:45 EDT 2014<b> | |
As you will notice the code is clearer and less verbose than its urllib2 | |
counterpart. | |
''' | |
import requests, console | |
port = ':9080' | |
currIP = '192.168.0.11' | |
#currIP = 'swosnick-pc' | |
url = 'http://'+ currIP + port + '/HelloWorldWeb/HelloWorldServlet' | |
console.clear() | |
print 'Trying to open url ' + url | |
response = requests.request('GET',url) | |
print (response.text) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment