How to make a simple Http request using Qt? The http request contains percent encoding in the URL

253 views Asked by At

I have one URL something as below:

QUrl url("https://example.com/send/?apikey=somekey&numbers=mobile&sender=XYZ&message=0000%20is%20your%20OTP%20to%20authenticate%20with%20Server:%20abc.com")

Now I call this URL as below:

QNetworkRequest networkRequest(url);
QNetworkAccessManager manager;
QEventLoop event;
QObject::connect(&manager, &QNetworkAccessManager::finished, &event, &QEventLoop::quit);
auto* const pResponse = manager.get(networkRequest);
event.exec();
pResponse->deleteLater();
return pResponse->readAll();

However, the call doesn't succeed. Upon debugging I found out that, the "&message" part from URL which is

&message=0000%20is%20your%20OTP%20to%20authenticate%20with%20Server:%20abc.com

becomes

&message=0000 is your OTP to authenticate with Server: abc.com

Probably that's the cause of the failure. If I copy paste the URL in the browser, it works fine.

How to make this request a success?
Though I have coded as of it's a blocking call, actually my requirement is to just invoke the above URL.

Update: This problem is fixed by itself. The website, where I was making an API call, was following certain template. I was missing a fullstop "." at the end. Upon adding that, it started working.

0

There are 0 answers