开发者

How do you directly write to a request body in Python

I am currently implementing code to call out to an API where the pos开发者_开发百科t request body needs to contain several columns of data in csv format.

e.g.

Col1, Col2, Col3

1, 2, 3

4, 5, 6

etc, with the content type header is set to 'text/csv'

How do I directly write to the request body?

I have a coworker who is doing the same thing as I am in Java and the Apache httpclient lib simply has a setRequestBody method.

Is there something similar in httplib, urllib (1,2) or pyCurl? Thanks.


Any HTTP client will give you some way to set the request body. For example, httplib.HTTPConnection.request takes an optional body parameter that allows you to pass request data. Same with urllib2.urlopen (there it's called data). I've never used PycURL myself but it definitely provides some way to include a body in the request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜