K
K
Kamo Petrosyan2017-03-19 00:41:38
Python
Kamo Petrosyan, 2017-03-19 00:41:38

Why is QUERY_STRING empty on POST request?

A GET request gives a normal QUERY_STRING, unlike a POST request.
Proper form

<form action="" method="post">
    <div class="input-group"><input type="text" name="first_name" placeholder="Имя" required></div>
    <div class="input-group"><input type="text" name="last_name" placeholder="Фамилия" required></    
    <div class="input-group">
        <button class="button" type="submit" onclick="testPhone(this.value);">Отправить</button>
    </div>
</form>

And the environ part:
'REQUEST_METHOD': 'POST', 'PATH_INFO': '/comment/', 'HTTP_ORIGIN': 'localhost', 'SERVER_PROTOCOL': 'HTTP/1.1', 'QUERY_STRING': 'regid=asd',

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Ivanov, 2017-03-19
@Fly3110

QUERY_STRING is the query string (the one after the last slash). With a post request, the parameters are passed in the body of the request, while the query string is most often empty

K
Kamo Petrosyan, 2017-03-19
@Haikson

I saw a lot of words, but there was no answer.

request_body_size = int(environ.get('CONTENT_LENGTH', 0))
if request_body_size:
    request_body = dict(urlparse.parse_qs(urllib.unquote(environ['wsgi.input'].read(request_body_size)).decode('utf-8')))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question