2015-11-11 102 views
-1

我需要把下面的curl命令轉換到Python 2.7:沒有捲曲到Python 2.7

curl -X POST --data-binary @myfile http://127.0.0.1/process/my/data 

我GOOGLE了這一點,但我只找到張貼的字段或文件,而不是發送的內容的例子文件寫入請求的body

+0

爲什麼-1?你能解釋一下? – leonardorame

回答

0

對於那些有興趣,這裏的答案:

# -*- coding: utf-8 -*- 
import httplib2 

h = httplib2.Http(".cache") 
resp, content = h.request("http://127.0.0.1/requests", 
    "POST", body="Here is the content of the file you want to post", 
    headers={'Content-type': 'application/json'} 
    )  
print resp