infection...

python 2.7 에서 rest api 확인 본문

Develop/ETC

python 2.7 에서 rest api 확인

돗거노인 2014. 12. 5. 10:10
#-*- coding: utf-8 -*-
__author__ = 'future'

##########################################################################################
import sys
import json
import httplib
import urllib

##########################################################################################
def existAccountName(host, port, username):
	params = urllib.urlencode({'username': username})
	headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
	conn = httplib.HTTPConnection(host=host, port=port)
	conn.request("POST", "/LBSNS/api/account/existAccountName", params, headers)
	response = conn.getresponse()
	# print response.status, response.reason
	data = response.read()
	conn.close()
	rdict = json.loads(data)
	return rdict


##########################################################################################
def test():
	import pprint
	host = '127.0.0.1'
	port = 8080

	# userAuth
	print "회원명 중복확인 : existAccountName('test')"
	print existAccountName(host, port, 'test')



##########################################################################################
if __name__ == '__main__':
	test()


restapi 전체 점검을 위해 궁리를 하다가 일일히 하나하나 확인하기보다 한번에 쫙확인할수있는 방법을 

발견 python으로 구성 하여 한번에 돌림 


원본 출처 : http://mcchae.egloos.com/viewer/11143246