2

This is my program. In this program I want to send request to a website (for example: http://www.adobe.com/products/muse.html)
I want to show the html code that return me in plain text box.

QUrl url("http://www.adobe.com/products/muse.html")

I want to give html code in "thisfile"

file.setFileName("thisfile.html");

if (!file.open(QIODevice::WriteOnly))
{
    std::cerr << "Error: Cannot write file "
    << qPrintable(file.fileName()) << ": "
    << qPrintable(file.errorString()) << std::endl

    return false;
}

http.setHost(url.host(),80);
http.post(url.toString(),"term=yyyy&loc=en_us&siteSection=products%3Amuse",&file);

This code doesn't work correctly and when I show the file give me false html code. What do I have to do?

Bart
  • 19,692
  • 7
  • 68
  • 77

2 Answers2

1

Use http.get() instead of http.post() as POST method requires to set other Headers used by server.

QHttp::get() method is asynchronous too.

As your case is simple enough just to retrieve HTML response, you should go for HTTP GET IMHO. See difference between GET and POST method.

And if you have to use HTTP POST only, then check this.

Community
  • 1
  • 1
Ammar
  • 1,947
  • 14
  • 15
0
 QNetworkRequest request;
 request.setUrl(QUrl("thisfile.html"));

 QNetworkReply *reply = manager->post(request, "term=yyyy&loc=en_us&siteSection=products%3Amuse");
 connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));

Look at QNetworkAccessManager at qt docs

You have to read information and save it to file at readyRead function

TheHorse
  • 2,787
  • 1
  • 23
  • 32