"""
payload = ... your payload ...
stream = StringIO(payload)
client.post(url,
CONTENT_TYPE='text/json',
CONTENT_LENGTH=len(payload),
wsgi.input = stream)
"""
It does not work.
在 2006年10月4日星期三UTC+8上午8时46分46秒,Russell Keith-Magee写道:
>
> On 10/4/06, Mikeal Rogers <[email protected] <javascript:>> wrote:
> >
> > I'm a little confused as to how to really use the test client for a
> > json-rpc request.
> >
> > I need to send a serialized object in the body, but the method seems
> > to be designed to simulate form post and may not contain this option.
>
> This is correct; the intention of the test client is to make it easy
> to stimulate Django responses to GET and POST requests without having
> to manually construct the request from scratch. Since the most common
> use case is GETting a page and POSTing a form, these are the use cases
> that are addressed by the test API.
>
> > Is there a way to do this that I'm missing or does this need to be
> > added.
>
> It's entirely possible that something needs to be added. As it says in
> the docs - the test framework is new and under development. So far, it
> has met _my_ needs - after all, I wrote it - but if there is a use
> case I have missed, I'm happy to do what I can to accommodate it.
>
> I'm not particularly familiar with the requirements of json-rpc - from
> a quick look at the website, it looks like what you need is to be able
> to compose a POST request that isn't multipart.
>
> You can do this using the extra kwargs to override the default POST
> dictionary:
>
> payload = ... your payload ...
> stream = StringIO(payload)
> client.post(url,
> CONTENT_TYPE='text/json',
> CONTENT_LENGTH=len(payload),
> wsgi.input = stream)
>
> You could also use client.request() - this is essentially the same
> approach, but doesn't assume any POST-like defaults.
>
> Now - obviously this isn't the cleanest API. I'm hesitant to add a
> specific 'json-rpc' interface to Client - this would lead to a
> proliferation of interfaces for protocols (xml-rpc, soap,...).
> However, I could be easily convinced to add a generic solution -
> something like:
>
> Client.raw_post(path, payload, payload_type='text/json')
>
> if it will satisfy the general RPC testing use case. Alternative
> suggestions are also welcome.
>
> > I think most of my confusion surrounding this is that I'm used to
> > using httplib to make these requests, but the client test tool seems
> > to make it's requests directly to the request handler apis. A note
> > about this in the documentation would really be helpful since I
> > wouldn't have guessed this without looking through the source.
>
> I'm not sure talking about the internals would improve the
> documentation. However, it is probably worth highlighting that the
> Client interface is slightly different to that of httplib. Raise an
> enhancement request for clarification of the docs, and assign it to me
> (russellm).
>
> Yours,
> Russ Magee %-)
>
>
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/eb0f3eb6-ae2e-4762-ae31-6147b44658ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.