[SOLVED] Can't understand howto send HTTP GET request with authentication
Example of site API usage: http://myanimelist.net/modules.php?go=api#animemangasearch
I tried to do GET request like POST, explained here: http://developer.qt.nokia.com/forums/viewthread/10771/#60273
but I didn't understand how to pass authentication.
Here is code example (based on ZapB's example, i rewrite only login function):
@void network::login( const QString& userName, const QString& password )
qDebug() << "Attempting to login with Username =" << userName << "and password =" << password;
m_userName = userName;
QNetworkRequest request; request.setUrl( QUrl( "http://myanimelist.net/api/anime/search.xml?q=bleach" ) ); request.setRawHeader( "User-Agent", "ZapB's QtDevNet Client 0.1" ); request.setHeader( QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded" ); QNetworkReply* reply = m_nam->get(request); connect( reply, SIGNAL( finished() ), SLOT( _q_onLoginRequestFinished() ) ); connect( reply, SIGNAL( metaDataChanged() ), SLOT( _q_onLoginMetaDataChanged() ) ); connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( _q_onLoginRequestError( QNetworkReply::NetworkError ) ) );
And I get such errors:
@Attempting to login with Username = "my_nick" and password = "my_pass"
"Loging request failed: Unauthorized."
Error when logging in: "Host requires authentication"
void network::_q_onLoginRequestFinished() @
Thanks for advise.
as mentioned you need to be authenticated first to able to use this service
you should first authorize your app to be able to use the services
if all you want is to learn you can try to send request to "google weather api":http://www.google.com/ig/api?weather=london for example and you'll find it's working
if you wanna use the services of this site, check first what's needed to authorize your app so you can use the services
Emmm... I'm registered on this site, but I didn't understand what you mean with "authorize your app".
You mean masking my app as browser?
it depends on how the services are made, but it's something like that
I just need to replace my url string to:
More about it: http://doc.qt.nokia.com/4.7-snapshot/qurl.html#setAuthority