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…
↧