97 lines
3.0 KiB
C++
97 lines
3.0 KiB
C++
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QJsonValue>
|
|
#include <QJsonArray>
|
|
|
|
#include "srunnable.h"
|
|
#include "data.h"
|
|
|
|
extern void Debug(QString _strFilename,QString _strData);
|
|
|
|
SRunnable::SRunnable()
|
|
{
|
|
m_pstrOut = 0;
|
|
}
|
|
|
|
SRunnable::~SRunnable()
|
|
{
|
|
|
|
}
|
|
|
|
void SRunnable::run()
|
|
{
|
|
QTcpSocket socket;
|
|
socket.connectToHost("202.179.179.16",80);
|
|
if(!socket.waitForConnected())
|
|
{
|
|
qDebug() << "Error: " << socket.errorString();
|
|
}
|
|
socket.write(QString("POST /api/reply/list.json HTTP/1.1\r\n"
|
|
"Host: comment.news.naver.com\r\n"
|
|
"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0\r\n"
|
|
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
|
|
"Accept-Language: ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3\r\n"
|
|
"Accept-Encoding: deflate\r\n"
|
|
"Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n"
|
|
"charset: utf-8\r\n"
|
|
"Content-Length: " + QString::number(m_strParam.length()) + "\r\n"
|
|
"Connection: keep-alive\r\n"
|
|
"Pragma: no-cache\r\n"
|
|
"Cache-Control: no-cache\r\n\r\n" + m_strParam).toUtf8());
|
|
QByteArray byArray;
|
|
while (socket.waitForReadyRead())
|
|
{
|
|
byArray += socket.readAll();
|
|
}
|
|
|
|
QJsonDocument d;
|
|
{
|
|
QJsonParseError error;
|
|
int index = byArray.indexOf("{");
|
|
byArray=byArray.mid(index-2);
|
|
bool bFlag = true;
|
|
QString strOut;
|
|
while(bFlag)
|
|
{
|
|
strOut += byArray.left(8188);
|
|
byArray=byArray.mid(8192);
|
|
if (byArray.size() <= 8192)
|
|
{
|
|
bFlag = false;
|
|
strOut += byArray;
|
|
}
|
|
}
|
|
strOut = strOut.replace("\r\n","").replace("\n","");
|
|
if (strOut.length() <= 0 ) return;
|
|
d = QJsonDocument::fromJson(strOut.trimmed().toUtf8(),&error);
|
|
if (error.error != 0)
|
|
{
|
|
qDebug() << error.errorString();
|
|
Debug("reply.json",strOut);
|
|
exit(0);
|
|
}
|
|
}
|
|
|
|
QString astrOut[E_REPLY_MAX];
|
|
foreach(QJsonValue value ,d.object().value("message").toObject().value("result").toObject().value("commentReplies").toArray())
|
|
{
|
|
QJsonObject obj = value.toObject();
|
|
int i= E_REPLY_USER_ID;
|
|
while (i < E_REPLY_MAX)
|
|
{
|
|
if (i <= E_REPLY_CONTENT)
|
|
astrOut[i] = obj[g_strJsonReplyHead[i]].toString();
|
|
else
|
|
astrOut[i] = QString::number(obj[g_strJsonReplyHead[i]].toInt());
|
|
i++;
|
|
}
|
|
for (i = 0; i < E_REPLY_MAX;i++)
|
|
{
|
|
QString strOut = g_strJsonReplyHead[i] + " : " + astrOut[i];
|
|
m_pstrOut->push_back(strOut);
|
|
}
|
|
m_pstrOut->push_back("");
|
|
}
|
|
socket.close();
|
|
}
|