2015-05-18 17 views
1

我有一個簡單的python http監聽服務器,如下所示。從Bottle服務器訪問HTTP POST數據

from bottle import route, run 

@route('/',method='POST') 
def default(): 
    return 'My first bottle program.' 

run(host='192.168.132.125', port=1729) 

如果我從另一臺服務器的一些數據(一個JSON文件)的POST如下

curl -X POST -d @data_100 http://192.168.132.125:1729/ 

我得到的輸出

My First Bottle Program 

現在,我想我的瓶服務器將發佈的JSON文件的內容轉儲到服務器上的文件夾。我可以如何實現此目的。

+0

有在這裏訪問的表單數據文檔:http://bottlepy.org/docs/dev/tutorial.html#html-form - 處理 –

回答

2

你可能想看看水瓶built-in json property

由於沒有錯誤檢查,它會是這個樣子:

@route('/', method='POST') 
def default(): 
    json_text = request.json 
    with open('/path/to/file', 'wb') as f: 
     f.write(json_text) 
    return 'My first bottle program.'