Skip to content

Commit

Permalink
可以从web和android 向服务器提交数据
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox.Lee committed Nov 26, 2012
1 parent fc7c5b0 commit 20b835b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 21-P297-ch9/get2inputsapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import android
from urllib.parse import urlencode
from urllib.request import urlopen

server_title = 'Which server should i use'
server_msg = "Plse confirm the server address/name to use for your athlete's timing data:"
timing_title = 'Enter data'
timing_msg = 'Provide a new timing value:'
web_server = 'http://192.168.1.180:8082'
add_time_cgi = '/cgi-bin/add_timing_data.py'

app = android.Android()

def send_to_server (url, post_data=None):
if post_data:
page = urlopen(url,urlencode(post_data).encode('utf-8'))
else:
page = urlopen(url)
return(page.read().decode('utf8'))

resp = app.dialogGetInput(server_title,server_msg,web_server).result

if resp is not None:
web_server = resp
resp = app.dialogGetInput(timing_title,timing_msg).result

if resp is not None:
new_time = resp
send_to_server(web_server+add_time_cgi,{'Timingvalue':new_time})

21 changes: 21 additions & 0 deletions 21-P297-ch9/webapp/cgi-bin/add_timing_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import cgi
import os
import time
import sys
import YATE

print (YATE.start_response('text/plain'))
addr = os.environ['REMOTE_ADDR']
host = os.environ['REMOTE_HOST']
method = os.environ['REQUEST_METHOD']
cur_time = time.asctime(time.localtime())

print (host+", "+addr+", "+cur_time+": "+method, file=sys.stderr)

form = cgi.FieldStorage()

for each_form_item in form.keys():
print (each_form_item + '->' + form[each_form_item].value,
end=' ', file=sys.stderr)
print (file = sys.stderr) #在标准错误输出上换行
print ('OK.')

0 comments on commit 20b835b

Please sign in to comment.