如何针对python HTTPConnection读取()/ write()?

时间:2021-06-17 21:08:33

I've got python code of the form:

我有以下形式的python代码:

(o,i) = os.popen2 ("/usr/bin/ssh host executable")  
ios = IOSource(i,o)

Library code then uses this IOSource, doing writes() and read()s against inputstream i and outputstream o.

然后,库代码使用此IOSource,对输入流i和输出流o执行write()和read()。

Yes, there is IPC going on here.. Think RPC.

是的,这里有IPC。想想RPC。

I want to do this, but in an HTTP fashion rather than spawning an ssh.

我想这样做,但是以HTTP方式而不是产生ssh。

I've done python http before with:

我之前做过python http:

conn=httplib.HTTPConnection('localhost',8000)  
conn.connect()  
conn.request('POST','/someurl/')  
response=conn.getresponse()  

How do I get the inputstream/outputstream from the HTTPConnection so that my lib code can read from/write to just like the ssh example above?

如何从HTTPConnection获取inputstream / outputstream,以便我的lib代码可以读取/写入,就像上面的ssh示例一样?

1 个解决方案

#1


for output:

output = response.read()

http://docs.python.org/library/httplib.html#httpresponse-objects

for input: pass your data in the POST body of your request

输入:在您的请求的POST正文中传递您的数据

#1


for output:

output = response.read()

http://docs.python.org/library/httplib.html#httpresponse-objects

for input: pass your data in the POST body of your request

输入:在您的请求的POST正文中传递您的数据