Django receives incomplete POST data

Solution for Django receives incomplete POST data
is Given Below:

I am posting json-formatted data to the backend written with Django 3.1.2. However, the data does not seem to received correctly.

js code:

var httpRequest = new XMLHttpRequest();"POST", "http://" + + "/upload/", true);
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpRequest.send(encodeURI("data=" + json));
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {


data = request.POST.get('data')
f = open('data.txt', 'w+')

The data written in the file is incomplete. Nor is it complete when I try to print it. What might be the problem? Is it because the json string I post is too long?

I managed to solve the problem by making this little change with my python code:

# data = request.POST.get('data')
data = request.body.decode('utf-8')

Nevertheless, I still do not understand why this works in my case.