Hi,
I have to call a php file with POST request simultaneoulsy for some n times. For this I am using QThread and QHttp. Here is the code.
The thread part
for(int i = 0;i < noOfThreads; i++)
{
MyThread *t = new MyThread();
connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
t->run();
}
for(int i = 0;i < noOfThreads; i++)
{
MyThread *t = new MyThread();
connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
t->run();
}
To copy to clipboard, switch view to plain text mode
The Http Part
op->clearPendingRequests();
for(int i=0;i<n;i++) {
header.setValue( "Host", ipAddress ) ;
header.setContentType( "application/x-www-form-urlencoded" ) ;
http.
request(header,
QVariant(log).
toByteArray());
}
op->clearPendingRequests();
for(int i=0;i<n;i++) {
QString log = GenerateLog();
QHttpRequestHeader header( "POST", "/somephpfile.php" ) ;
header.setValue( "Host", ipAddress ) ;
header.setContentType( "application/x-www-form-urlencoded" ) ;
http.request(header,QVariant(log).toByteArray());
}
To copy to clipboard, switch view to plain text mode
The above code is not working. Can someone please help?
Thanks.
Oh by the way here is my run () function
void MyThread::run()
{
mutex.lock();
Http list(ipAddress, n);
list.SetHost(ipAddress);
list.info();
mutex.unlock();
}
void MyThread::run()
{
mutex.lock();
Http list(ipAddress, n);
list.SetHost(ipAddress);
list.info();
mutex.unlock();
}
To copy to clipboard, switch view to plain text mode
I am new to both threading and http stuff. It would be great if some one can suggest some tutorial or help.
Thanks a lot.
Bookmarks