用Python的POST测试RESTful API
||
我正在尝试测试我正在使用的RESTful接口(我正在使用该接口:codeigniter-restserver),并且我想使用Python。
ѭ0似乎工作正常,但我对ѭ1遇到麻烦。我不是在问这个库的来龙去脉,而是在尝试
弄清楚如何用Python测试ѭ1。这是我所拥有的:
import httplib, urllib
params = urllib.urlencode({
\'sentence\': \'esta es una frase\',
\'translation\': \'this is a sentence\'
})
headers = {
\"Content-type\": \"application/x-www-form-urlencoded\",
\"Accept\": \"text/plain\"
}
conn = httplib.HTTPConnection(\"localhost:80\")
conn.request(\"POST\", \"/myapp/phrase\", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()
此脚本足以作为测试“ 1”的方法吗?我在SO上看到了很多关于人们寻找GUI工具来执行此操作的要求(Firefox插件等)
但是对我而言,首先构建RESTful应用程序的重点是拥有一个我可以编写脚本的API以快速修改数据库。 (用数据填充
从JSON文件中获取)。
使用这种基于Python的方法是否正确?
谢谢
没有找到相关结果
已邀请:
3 个回复
艾食魄轻县
闪票仇门韧
糕泰灌
更多示例:https://github.com/kimmobrunfeldt/nap#examples 免责声明:我写午睡。