HTTP 調用

運行環境

  • Linux
  • Apache (mod_python)

Apache 端

import datetime def index(req, an_arg='default'): now = datetime.datetime.now() ans = now.strftime("%Y-%m-%d %H:%M:%S") req.content_type = 'text/plain' return ans

客戶端

#!/usr/bin/env python import sys import httplib webPage = '/index.html' if len(sys.argv) > 1: webPage = "/python/" + sys.argv[1] conn = httplib.HTTPConnection("127.0.0.1") conn.request("GET", webPage) r1 = conn.getresponse() if r1.status==200: data = r1.read() print data else: print r1.status, r1.reason conn.close()