UltraScan III
us_http_post.cpp
Go to the documentation of this file.
1 #include "us_http_post.h"
3 
4 US_HttpPost::US_HttpPost( const QString& url, const QString& request ) : QObject()
5 {
6  QNetworkAccessManager* manager = new QNetworkAccessManager( this );
7  QNetworkRequest httpPost;
8 
9  httpPost.setHeader( QNetworkRequest::ContentTypeHeader,
10  QString( "application/x-www-form-urlencoded" ) );
11  httpPost.setUrl( QUrl( url ) );
12 
13  reply = manager->post( httpPost, request.toAscii().data() );
14 
15  connect( reply, SIGNAL( finished ( void ) ),
16  this, SLOT ( postFinished( void ) ) );
17 
18  connect( reply, SIGNAL( error ( QNetworkReply::NetworkError ) ),
19  this, SLOT ( postError( QNetworkReply::NetworkError ) ) );
20 
21 }
22 
24 {
25  int error = reply->error();
26 
27  if ( error == QNetworkReply::NoError )
28  emit US_Http_post_response( reply->readAll() );
29 }
30 
31 void US_HttpPost::postError( QNetworkReply::NetworkError error )
32 {
33  static int count = 0; // Just send the first error
34 
35  if ( count == 0 )
36  {
37  count++;
38  QString err = QString( "9-Network Error (%1): " ).arg( error ) + reply->errorString();
39  emit US_Http_post_response( err );
40  }
41 }
42