Headers and Cookies of QNetworkRequest - really necessary ?



  • This question is not so much about Qt itself, hopefully it's not a problem.
    I'm writing a program to log into a game a get some information from the account. Studying the network tab in chrome's dev options, I got the headers and cookies of the requests and made my own post and get requests, and everything works fine.
    The requests contain 13 headers, typically : Accept,Accept-Encoding,Accept-Language,Cache-Control,Connection,Content-Length,Content-Type,Host,Origin,Pragma,Referer,Upgrade-Insecure-Requests,User-Agent , plus the Cookie header which contains at least 3 cookie values. Out of curiosity I removed all of these, and the reply content is the exact same as before. So, do I actually have to set all this headers to the values displayed in dev options ? Is there a benefit of setting these up ?



  • You don't have to set headers. What they affect is going to depend on the details of the implementation on the server. For example, if you set User-Agent to an old version of Explorer you might instead get a page telling you the site is incompatible. It sounds like in your case you can simply omit the headers without issue. You may be making your app more fragile, since the site's handling of those headers could change at any time to matter, but since my recollection is that you are writing screen-scraping software you have bigger fragility issues anyway.



  • Thanks Chris :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.