t-artistik / qtscriptgenerator

Automatically exported from code.google.com/p/qtscriptgenerator
0 stars 0 forks source link

setRawHeader doesn't work when using QNetworkAccessManager with QNetworkRequest #75

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,
sometimes some servers require specific headers to respond properly. Like 
User-Agent for example. Using Amarok's scripting engine I'm trying to connect 
to the server with custom User-Agent header. Therefore the 'Downloader' helper 
is of no use.

So I tried using QNetworkAccessManager with QNetworkRequest to set these 
headers. I saw this example: 
http://doc.trolltech.com/latest/qnetworkaccessmanager.html#details and that's 
exactly what I need.
but when I executed this code:

var request = new QNetworkRequest(QUrl.fromEncoded( new 
QByteArray("http://www.google.com"), QUrl.StrictMode ));
request.setRawHeader("User-Agent", "Testagent");
request.setRawHeader("test-header", "test test");
var manager = new  QNetworkAccessManager();
reply = manager.get(request);

I didn't get the desired results (the url is not actually the google.com but 
some other server which requests a specific user agent)

so I fired up wireshark and saw that Amarok is still sending 'User-Agent: 
Mozilla/5.0' although I set it to 'Testagent'. Not just that but even the 
'test-header: test test' was not added to the headers.

I'm currently using latest Amarok 2.4 from GIT and Qt 4.5.3

(also as a workaround I tried with sockets, but they are also not working: 
http://code.google.com/p/qtscriptgenerator/issues/detail?id=65 )

Original issue reported on code.google.com by cotko...@gmail.com on 25 Dec 2010 at 9:23

GoogleCodeExporter commented 8 years ago
I accidentally deleted the ',' between the url and QUrl.ScrictMode in the 
example code above

Original comment by cotko...@gmail.com on 25 Dec 2010 at 9:39