I can not get the all data from the website by QNetworkAccessManager



  • I can not get the all data from the website by QNetworkAccessManager.if I use get function ,I can get the all data from the website,but if I use post function,It faild.just can get few data; if the website is to long ,it can get few data.if the website data is short,Ican get all.

    I find "response headers" ,is has "Transfer-Encoding:chunked". how can I solve it. who can help me ?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should describe more precisely what you are currently doing e.g. accessing a REST service ? Sharing your code would also be good idea.



  • @SGaist
    echo "reqData=PD94bWwgIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IkdCSyIgPz4KPENNUz4KPGViPgo8cHViPgo8VHJhbnNDb2RlPlFQRDwvVHJhbnNDb2RlPgo8Q0lTPjE3MDY5MDAwMDIyMzkzMDwvQ0lTPgo8QmFua0NvZGUMTAyPC9CYW5rQ29kZT4KPElEPmZyY3M0LnkuMTcwNjwvSUQCjxUcmFuRGF0ZT4yMDE1MDcyODwvVHJhbkRhdGUCjxUcmFuVGltZT4xNTM5MTY8L1RyYW5UaW1lPgo8ZlNlcW5vPjIwMTUwNzI4MTUzOTE2PC9mU2Vxbm8CjxSZXRDb2RlPjA8L1JldENvZGUCjxSZXRNc2cPC9SZXRNc2cCjwvcHViPgo8b3V0Pgo8QWNjTm8MTcwNjAyMjAwOTAyMDA0NDg3MjwvQWNjTm8CjxBY2NOYW1lPsDZz7rI19TPtNPVzbm6tc3J88v8z7w8L0FjY05hbWUCjxDdXJyVHlwZT5STUI8L0N1cnJUeXBlPgo8QXJlYUNvZGUPC9BcmVhQ29kZT4KPE5leHRUYWc+PC9OZXh0VGFnPgo8VG90YWxOdW0MzwvVG90YWxOdW0CjxSZXBSZXNlcnZlZDEPC9SZXBSZXNlcnZlZDECjxSZXBSZXNlcnZlZDIPC9SZXBSZXNlcnZlZDICjxyZD4KPERyY3JmPjI8L0RyY3JmPgo8Vm91aE5vPjA8L1ZvdWhObz4KPEFtb3VudD4zMDAwMDA8L0Ftb3VudD4KPFJlY2lwQmtObz4wPC9SZWNpcEJrTm8+Cjx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HlwZT5STUI8L0N1cnJUeXBlPgo8QXJlYUNvZGUPC9BcmVhQ29kZT4KPE5leHRUYWc+PC9OZXh0VGFnPgo8VG90YWxOdW0MzwvVG90YWxOdW0CjxSZXBSZXNlcnZlZDEPC9SZXBSZXNlcnZlZDECjxSZXBSZXNlcnZlZDIPC9SZXBSZXNlcnZlZDICjxyZD4KPERyY3JmPjI8L0RyY3JmPgo8Vm91aE5vPjA8L1ZvdWhObz4KPEFtb3VudD4zMDAwMDA8L0Ftb3VudD4KPFJlY2lwQmtObz4wPC9SZWNpcEJrTm8+CjxSZWNpcEFjY05vPjYyMjIwODE3MDI4OTk5OTg2MTg8L1JlY2lwQWNjTm8+CjxSZWNpcE5hbWU+tqG9ozwvUmVjaXBOYW1lPgo8U3VtbWFyeT7N+NeqPC9TdW1tYXJ5Pgo8VXNlQ04+u7/7jwvVXNlQ04+CjxQb3N0U2NyaXB0PjwvUG9z_______________

    this is my QT code
    class TT : public QObject
    {
    Q_OBJECT
    public:
    static QString getHtml(QString url)
    {
    QNetworkAccessManager *manager = new QNetworkAccessManager();
    QNetworkReply reply = manager->get(QNetworkRequest(QUrl(url)));
    QByteArray responseData;
    QEventLoop eventLoop;
    connect(manager, SIGNAL(finished(QNetworkReply
    )), &eventLoop, SLOT(quit()));
    eventLoop.exec(); //block until finish

    	responseData = reply->readAll();
    	
    	return QString(responseData);
    }
    static QString postHtml(QString url,QByteArray post_data)
    {
    	QNetworkAccessManager *manager = new QNetworkAccessManager();
    	QNetworkRequest req;
    	req.setUrl(QUrl(url));
    	req.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    	req.setRawHeader("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
    	req.setRawHeader("Accept-Language", "zh-CN,zh;q=0.8");
    	QNetworkReply *reply = manager->post(req,post_data);
    	QByteArray responseData;
    	QEventLoop eventLoop;
    
    	
    	connect(manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
    	eventLoop.exec();       //block until finish
    
    
    	 QVariant var = reply->rawHeader("Content-Length");
    	QString r="";
    	while(!reply->atEnd()){
    		r+=reply->read(1024);
    	}
    
    	QString rr=r;
    
    	responseData = reply->readAll();
    	
    	r=responseData.data();
    	return r;
    }
    

    };

    the php code is my demo. the website which I want to get the data is like that.



  • @SGaist I use qt 4.8 and in VS2010



  • @SGaist 3q . I get it


  • Lifetime Qt Champion

    What do you mean by "I get it" ?


Log in to reply
 

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