Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

getting status code 0 for HTTP post request in qt 5.2

$
0
0
Hi, I have built the web services in Ruby on Rails returning Json data, I have checked it through chrome addin and it is working good, returning correct status code on success. So, here I am trying to access these web service but I am getting wrong status code which is 0. Here is my code…but I could not find where I did wrong as I tried to find the problems with logs.  QNetworkAccessManager networkManager;         QNetworkAccessManager mgr;         QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));         qDebug() << "Called the C++ slot with message:sssss";         QUrl url;         QByteArray postData;         url.setUrl("http://localhost:3000/api/v1/sessions");         QNetworkRequest request(url);           QString postKey = "email";         QString postValue = "abcd@abcd.com";         QString postKey1 = "password";         QString postValue1 = "abcde12345";           postData.append(postKey).append("=").append(postValue).append("&").append(postKey1).append("=").append(postValue1);         QNetworkReply *reply= networkManager.post(request,postData);           QVariant statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );         int status = statusCode.toInt();         qDebug() << "Called the C++ slot with message:Correct" << status;           if ( status==200 )             qDebug() << "Called the C++ slot with message:Correct";         return;           if ( status != 200 )         {             QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();             qDebug() << reason;         }       } Thanks…

Viewing all articles
Browse latest Browse all 4972

Trending Articles