Skip to content

Instantly share code, notes, and snippets.

@ltddev
Created March 27, 2014 20:22
Show Gist options
  • Save ltddev/9817669 to your computer and use it in GitHub Desktop.
Save ltddev/9817669 to your computer and use it in GitHub Desktop.
HttpServletInvocationRequests
'''
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