Results 1 to 5 of 5

Thread: how to login to the application using JSON data in Qt

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2015
    Location
    India
    Posts
    16
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default how to login to the application using JSON data in Qt

    I am trying to access data from url string https://10.201.58.88:2342/kirk/1.0/h...physicaldrives but it is showing me HOst require Authantication
    so I have to login for my app using JSON Url https://10.201.58.88:2342/kirk/1.0/session
    {
    "user":
    {
    "uname": "root",
    "kirk_access": "ADMIN",
    "hosts":
    [
    {
    "host_key": "824D103048EB0116A",
    "ip": "10.201.58.88",
    "port": "2342",
    "hostname": "localhost.localdomain",
    "is_local_host": "true",
    "auth_type": "host",
    "uname": "root",
    "config_type": "enterprise",
    "sys_access": "ADMIN"

    }
    ]
    },
    how to get Login and access data from https://10.201.58.88:2342/kirk/1.0/h...physicaldrives

    / QString USER_AGENT = "Mozilla/5.0";

    QUrl serviceURL("https://10.201.58.87:2342/kirk/1.0/session");
    QNetworkRequest request(serviceURL);


    request.setRawHeader("Host","10.201.58.88:2342");
    request.setRawHeader("host_key", "824D10304816A");
    request.setRawHeader("User-Agent", "Mozilla/5.0");
    request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    request.setRawHeader("Accept-Language", "en-US,en;q=0.5");
    request.setRawHeader("Accept-Encoding", " gzip, deflate");
    request.setRawHeader("Referer", "https://10.201.58.87:2342/ui/core/index.html");
    request.setRawHeader("Content-Type", "application/json;application/x-www-form-urlencoded");
    request.setRawHeader("Content-Length", "46");
    request.setRawHeader("Connection", "keep-alive");

    QByteArray usr = "root";
    QByteArray pwd = "abc@123";
    QByteArray jsonString = "{\"uname\":\"" +usr+"\", \"pwd\":\""+pwd+"\"}";


    Q QNetworkAccessManager manager;
    QEventLoop loop;
    connect(&manager, SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit()));
    reply = manager.post(request, jsonString);


    qDebug() << "post" << reply;
    qDebug() << "get" << manager.get(request);
    QByteArray response = reply->readAll();

    qDebug() << " response" << response;
    loop.exec();
    I have tried this but getting

    Starting ....build-layout-Desktop_Qt_5_5_1_MSVC2013_64bit-Debug\debug\layout.exe...
    post QNetworkReplyHttpImpl(0x2386790)
    get QNetworkReplyHttpImpl(0x365a50)
    response ""
    error "Unknown error"
    Last edited by Radhika; 3rd December 2015 at 10:56.

Similar Threads

  1. Correct POST html with JSON data
    By Mbded in forum Qt Programming
    Replies: 11
    Last Post: 23rd August 2015, 10:19
  2. Using JSON sample application
    By mania in forum Qt Programming
    Replies: 1
    Last Post: 23rd June 2015, 11:12
  3. How to load base64 image data from json in QT
    By phpkode in forum Qt Programming
    Replies: 4
    Last Post: 9th January 2015, 11:10
  4. model/view json data displaying
    By binaural in forum Qt Programming
    Replies: 5
    Last Post: 27th June 2012, 08:13
  5. Qt application settings in JSON
    By asvil in forum Qt-based Software
    Replies: 0
    Last Post: 5th March 2011, 21:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.