trying to get response from web service and encountering error 301

  • i send this post request with parameters: device_ID=1&pin_code=11111111 expecting to get xml response "true". but i get error code 301 every time. i have not any idea what the problem is
    Can anyone help me?

    web service address:

    QByteArray post = QByteArray("device_ID=1&pin_code=11111111");
        QNetworkRequest req = QNetworkRequest(QUrl(""));
        req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
        connect(network_access_manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(serviceRequestFinished(QNetworkReply*)));
        network_access_manager->post(req, post);
    void MainWindow::serviceRequestFinished(QNetworkReply *reply)
        if(reply->error() == QNetworkReply::NoError)
            receivedData = reply->readAll();
            QString myString(receivedData);
            msg->setText("Response: " + myString);
            msg->setText("Error: " + QString::number(int(reply->error())));

  • I had a quick look. Is there any reason you don't inlcude the scheme (http://) in the url?

  • it worked!
    i thought that is an optional phrase! because it worked in browser without "http://" too
    thank you

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    That's because web browsers default to http if you don't specify anything.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.