| 849 | .. admonition:: Testing RESTful web services |
| 850 | |
| 851 | Since web browsers are only designed to perform **GET** and **POST** |
| 852 | requests, the :attr:`~django.http.HttpRequest.POST` variable won't be accessible if you |
| 853 | performed a request with a http verb that is not **POST**, even if the |
| 854 | request body is url encoded. |
| 855 | |
| 856 | To access the submitted data, you need to use the |
| 857 | :attr:`~django.http.HttpRequest.body`, which contains the |
| 858 | raw body of the HTTP request. |
| 859 | |
| 860 | If you know the incoming request will be **x-www-form-urlencoded** or |
| 861 | **multipart/form-data** encoded, you can use the following method:: |
| 862 | |
| 863 | from cStringIO import StringIO |
| 864 | from django.http import QueryDict |
| 865 | from django.http.multipartparser import MultiPartParser |
| 866 | |
| 867 | |
| 868 | def parse_put_data(request): |
| 869 | content_type = request.META.get('CONTENT_TYPE') |
| 870 | if content_type.startswith('multipart'): |
| 871 | parser = MultiPartParser(request.META, StringIO(request.body), [], request.encoding) |
| 872 | post, files = parser.parse() |
| 873 | else: |
| 874 | post = QueryDict(request.body) |
| 875 | return post |
| 876 | |
| 877 | |
| 878 | |