February 10, 2012

Mr.FreakyJo Mr.FreakyJo
Lab Rat
43 posts

Write all data of an NetworkReply

 

I tried to write the data of an network reply but the file was empty.Here’s the code I used :

  1. QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
  2.  QVariant variant=reply->header(QNetworkRequest::LocationHeader);
  3.  QFile file("out.txt");
  4.  file.write(variant.typeName());

I want to read all the data to see how is stored so I can continue writing my program.

8 replies

February 10, 2012

task_struct task_struct
Hobby Entomologist
344 posts

You didn’t open file.

  1. QFile file("out.txt");
  2. file.open(QIODevice::WriteOnly);
  3. file.write(variant.typeName());

Also I guess you want to see content of header so you should use rawHeader

 Signature 

“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds

February 10, 2012

Mr.FreakyJo Mr.FreakyJo
Lab Rat
43 posts

Thank you.Now I have another problem.After a post request I receive some html code,I saw this with the help of Chrome.How do I extract that code from the QNetworkReply?I know how to get the headers but not this.Thank you again.

February 10, 2012

task_struct task_struct
Hobby Entomologist
344 posts

QNetworkReply inherits QIODevice [developer.qt.nokia.com] so I think it is like reading from file.

 Signature 

“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.”
- Linus Torvalds

February 10, 2012

Volker Volker
Robot Herder
5428 posts

readAll() gets you all the data received in the reply.

Also, if you connect to the finished() signal of the QNetworkAccessManager, that contains the reply in its argument, you don’t need the call to sender() then.

February 11, 2012

Mr.FreakyJo Mr.FreakyJo
Lab Rat
43 posts

I figured out.Thank you very much.

February 11, 2012

Mr.FreakyJo Mr.FreakyJo
Lab Rat
43 posts

After monitoring http request with the help off google chrome I see that a http post request is made by a script.I see that it’s initiator is game.js:17 (a javascript).Can I make a http request to that script or how can I do it?Is it necessary to use XMLHttpRequest?

February 12, 2012

Mr.FreakyJo Mr.FreakyJo
Lab Rat
43 posts

Here is an image from Chrome
http://imageshack.us/photo/my-images/641/96160298.png
This post call modifies the source code of the page(is returning a form with a sid key that I need).Is there a way to do this call with QNetworkHttpRequest?

February 12, 2012

Volker Volker
Robot Herder
5428 posts

You can always imitate what that script does and modify your own requests. Unfortunately there’s nothing else to add here. Self modifying code usually tends to be tricky to analyze.

 
  ‹‹ Is there a way to regenerate the files in webkit/WebCore/generated?      Prevent QWebView from blocking the application? ››

You must log in to post a reply. Not a member yet? Register here!