1

I want to send data through a post request but only those who are authenticated can do it. In django application I added the BasicAuthentication in settings.py

...
REST_FRAMEWORK = {
    'PAGE_SIZE': 10,
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.BasicAuthentication',
    )
}

and in Qt post authenticated to do so

...
QNetworkRequest request;
QUrl url("https://.../data/");
url.setUserInfo("username:password");
request.setUrl(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QString json = QString(...);
QNetworkReply *reply = m_manager->post(request, json.toUtf8());
...

As an error the server returns me -> Error transferring https://username:password@.../data/ - server replied: Bad Request.

I can not understand whether the problem lies in the way in which pass username: password or django app.

fhava
  • 23
  • 3

1 Answers1

0

Set user info just appends the "username:password" to the URL authority section. See the docs for an example. For HTTP basic authentication, you need to use something similar to this answer.

Community
  • 1
  • 1
martinarroyo
  • 9,389
  • 3
  • 38
  • 75