Sending parameters by get method to rest api
-
You are not doing any error management so you can't know what is happening.
-
@Axel-Spoerl
Thanks for your help
but it is not ok not only this case but also I changed the code a bit
but is not ok yet
changed code:QUrl url("http://localhost:59444/api/Getmojodi"); QNetworkRequest req1; const QByteArray basic_authorization =token.toUtf8().toBase64(); req1.setRawHeader(QByteArrayLiteral("Authorization"), basic_authorization); QUrlQuery uq; uq.addQueryItem("KalaCode","20101010131310"); url.setQuery(uq); req1.setUrl(url); QNetworkReply *rep= manager->get(req1); // blocking code starts here QEventLoop loop; QTimer timer; timer.setSingleShot(true); QObject::connect(&timer,&QTimer::timeout,&loop,&QEventLoop::quit); QObject::connect(rep, &QNetworkReply::finished, &loop, &QEventLoop::quit); timer.start(5000); loop.exec(); // end of blocking code if(!timer.isActive()) { QString val = rep->readAll(); QJsonDocument jDoc=QJsonDocument::fromJson(val.toUtf8()); QJsonObject obj = jDoc.object(); qDebug()<<val;//obj["mojodi"].toString(); }
@ali-aydin said in Sending parameters by get method to rest api:
but is not ok yet
if(!timer.isActive())
qDebug()<<val;
... and additionally to @SGaist why not tell us whether it times out or what it outputs?
-
Authentication, authorization and request management are three different stages that all can fail separately. The fact that you can authenticate does not mean that everything else is working.
-
Authentication, authorization and request management are three different stages that all can fail separately. The fact that you can authenticate does not mean that everything else is working.
-
The best place is the documentation: QNetworkReply::errorOccured.
-
The best place is the documentation: QNetworkReply::errorOccured.
@SGaist
@Axel-Spoerl
I changed slot that connected to finish signal like this :QByteArray bytes = R->readAll(); QString str = QString::fromUtf8(bytes.data(), bytes.size()); int statusCode = R->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qDebug() << QVariant(statusCode).toString();
and return 403 code it means forbidden.why?
-
-
@Axel-Spoerl
Yes I tried by postman and is ok -
@Axel-Spoerl
Yes I tried by postman and is ok@ali-aydin
Your platform/web server may/should have the ability to log all requests/responses to a log file? You might switch that on and see if anything helpful there? -
@ali-aydin
Your platform/web server may/should have the ability to log all requests/responses to a log file? You might switch that on and see if anything helpful there? -
@ali-aydin Look in your web server's documentation.
-
@ali-aydin Look in your web server's documentation.
-
I think you have to add 'Basic ' before your token when you set the Authorization header (or 'Bearer ' if you are doing bearer token auth). If things are working in Postman, check the 'Headers' tab of your request as to what is the actual value being sent for the Authorization.
-
I think you have to add 'Basic ' before your token when you set the Authorization header (or 'Bearer ' if you are doing bearer token auth). If things are working in Postman, check the 'Headers' tab of your request as to what is the actual value being sent for the Authorization.
@mchinand
Bearer must be added to the token.
in postman there is no header
in authorization tab
only added token and in parameters tab is only one parameter :KalaCode
in body tab username,password and grant_type
in the qt when I want to authenticate byQUrl url("http://localhost:594444/api/authenticate");
it returns "Hello"
but when i changing url toQUrl url("http://localhost:594444/api/Getmojodi" );
it does not work
-
I meant the 'Headers' tab of the Postman request:
The authorization header value above was automatically set when I added a (junk) username and password in the Auth tab:
-
Are you setting the Authorization the same in Qt as the value it is set in Postman? Your variables are 'basic_authorization' and 'token', is token just the token or is the token type prepended to it ('Basic ' or 'Bearer ')? Your variable is 'basic_authorization' but in your prior message, you mention adding 'Bearer' before the token, which auth method are you using?
-
Are you setting the Authorization the same in Qt as the value it is set in Postman? Your variables are 'basic_authorization' and 'token', is token just the token or is the token type prepended to it ('Basic ' or 'Bearer ')? Your variable is 'basic_authorization' but in your prior message, you mention adding 'Bearer' before the token, which auth method are you using?
-
@mchinand
i'm using url.setRawHeader() for add token to url and
and adding bearer to token
i don't use any auth method
how to use that?