stone9981/httpsqs

python 客户端

Opened this issue · 1 comments

# -*- coding: utf-8 -*-
#!/usr/bin/python
import urllib2
import urllib
import sys
def httpsqs_get(host, port,name,charset='utf-8'):
    data={'charset':charset,'name' : name, 'opt' : 'get'}
    url='http://'+host+':'+port+'/?'
    data=urllib.urlencode(data)
    getString=url+data
    req = urllib2.Request(getString)
    fd = urllib2.urlopen(req)
    str=fd.read()
    if str=='HTTPSQS_GET_END':
        print 'HTTPSQS_GET_END'
    else:
        return str
def httpsqs_put(host, port,name,data,charset='utf-8'):
    data={'charset':charset,'name' : name, 'opt' : 'put','data' : data}
    url='http://'+host+':'+port+'/?'
    data=urllib.urlencode(data)
    getString=url+data
    req = urllib2.Request(getString)
    fd = urllib2.urlopen(req)
    str=fd.read()
    if str=='HTTPSQS_PUT_OK':
        return 1
    else:
        return 0
#下面是调用方式
data=sfsdfasafasdfasdfadfasdfadsfsdf
srr=httpsqs_put('127.0.0.1','1218','test',data)
sss=httpsqs_get('127.0.0.1','1218','test')

保存为py文件即可

Original issue reported on code.google.com by ylj...@gmail.com on 13 Jun 2010 at 6:01

https://github.com/wendal/httpsqs4py

我的版本更完善些

Original comment by wendal1985@gmail.com on 6 Jul 2011 at 1:08