Hi all, I have strange problem with QNetworAccessManager.
I was trying to make a web service application with Qt with OAuth.
I manage to create my own OAuth service for my need based on QOAuth.
But the problem is not in OAuth.
The problem is in QNetworkAccessManager.
For example, there is this url that produced by OAuth,
if I open that url with QNetworkManager, like this
QNetworkAccessManager manager = new QNetworkAccessManager();
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
// this is just for illustration not real consumer key and signature, the link produced by my OAuth
QString url
= "https://www.my-example-site.com/oauth/content?oauth_consumer_key=1234567890&oauth_nonce=1824974157&oauth_signature=aBAy4KWZcs5762N4VPjiDj%2FtyqY%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1366080188&oauth_version=1.0";
QNetworkRequest request;
request.setUrl( url );
request.setRawHeader( "Content-Type", "application/x-www-form-urlencoded");
QNetworkReply *reply = manager->get( request );
QNetworkAccessManager manager = new QNetworkAccessManager();
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
// this is just for illustration not real consumer key and signature, the link produced by my OAuth
QString url = "https://www.my-example-site.com/oauth/content?oauth_consumer_key=1234567890&oauth_nonce=1824974157&oauth_signature=aBAy4KWZcs5762N4VPjiDj%2FtyqY%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1366080188&oauth_version=1.0";
QNetworkRequest request;
request.setUrl( url );
request.setRawHeader( "Content-Type", "application/x-www-form-urlencoded");
QNetworkReply *reply = manager->get( request );
To copy to clipboard, switch view to plain text mode
It gave error "Host Require Authentication", "Error 401", "oauth_problem=invalid_signature"
but, if I generate new url with my OAuth and open that link on firefox, it will produce correct result.
I also try libcurl for c++.
CURL* curl;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
// another illustration, not real consumer key and signature
curl_easy_setopt(curl, CURLOPT_URL, "https://www.my-example-site.com/oauth/content?oauth_consumer_key=1234567890&oauth_nonce=1824974157&oauth_signature=a9Vy4+CZcs5762N4VPjiDj%2FtyqY%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1366080200&oauth_version=1.0");
// curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_global_cleanup();
CURL* curl;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
// another illustration, not real consumer key and signature
curl_easy_setopt(curl, CURLOPT_URL, "https://www.my-example-site.com/oauth/content?oauth_consumer_key=1234567890&oauth_nonce=1824974157&oauth_signature=a9Vy4+CZcs5762N4VPjiDj%2FtyqY%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1366080200&oauth_version=1.0");
// curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &writeCallback);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_global_cleanup();
To copy to clipboard, switch view to plain text mode
It gave correct result and no error.
I also try QHttp.
connect(http, SIGNAL(requestFinished(int,bool)), this, SLOT(requestFinished(int,bool)));
http
->setHost
("https://www.my-example-site.com",
QHttp::ConnectionModeHttps);
http->get("/oauth/content?oauth_consumer_key=1234567890&oauth_nonce=1824974157&oauth_signature=a9Vy4+ABCDEF62N4VPjiDj%2FtyqY%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1366080300&oauth_version=1.0");
QHttp http = new QHttp();
connect(http, SIGNAL(requestFinished(int,bool)), this, SLOT(requestFinished(int,bool)));
http->setHost("https://www.my-example-site.com", QHttp::ConnectionModeHttps);
http->get("/oauth/content?oauth_consumer_key=1234567890&oauth_nonce=1824974157&oauth_signature=a9Vy4+ABCDEF62N4VPjiDj%2FtyqY%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1366080300&oauth_version=1.0");
To copy to clipboard, switch view to plain text mode
It also gave correct result and no error.
So, what is wrong with the way I use QNetworkAccessManager?
I try it in qtcreator with Qt 4.8 and Qt 5, but no luck.
They gave same error result.
I want to keep on using QNetworkAccessManager, but if I can't resolve this problem, what should I do?
Should I use curl or QHttp? or is there another network library that I can use?
thank you.
Bookmarks