A class which performs one simple HTTP request, expecting a text response (HTML, XML, whatever, but not binary data).
More...
|
void | completed (bool success, const QUrl &url, const QString &response, const QString &mimeType) |
| Emitted when the request is completed. More...
|
|
A class which performs one simple HTTP request, expecting a text response (HTML, XML, whatever, but not binary data).
Automatically handle proxies and HTTP redirections.
◆ QtlSimpleWebRequest() [1/2]
QtlSimpleWebRequest::QtlSimpleWebRequest |
( |
const QString & |
url = QString() , |
|
|
QObject * |
parent = 0 , |
|
|
QtlLogger * |
log = 0 , |
|
|
int |
maxResponseSize = 1000000 |
|
) |
| |
Constructor.
- Parameters
-
[in] | url | URL to get. If unspecified, you must call setUrl() before start(). |
[in] | parent | Optional parent object. |
[in] | log | Optional message logger. |
[in] | maxResponseSize | Maximum size in bytes of response (to avoid memory saturation). Default: 1 MB. |
◆ ~QtlSimpleWebRequest()
QtlSimpleWebRequest::~QtlSimpleWebRequest |
( |
| ) |
|
|
virtual |
◆ QtlSimpleWebRequest() [2/2]
QtlSimpleWebRequest::QtlSimpleWebRequest |
( |
| ) |
|
|
private |
◆ setUrl()
void QtlSimpleWebRequest::setUrl |
( |
const QString & |
url | ) |
|
Set the URL of the request.
Must be called before start(). Ignored otherwise.
- Parameters
-
[in] | url | URL of the request. |
◆ url()
QUrl QtlSimpleWebRequest::url |
( |
| ) |
const |
|
inline |
Get the URL of the request.
- Returns
- URL of the request.
◆ addCookie()
void QtlSimpleWebRequest::addCookie |
( |
const QString & |
name, |
|
|
const QString & |
value |
|
) |
| |
Add a cookie for the request.
Must be called before start(). Ignored otherwise.
- Parameters
-
[in] | name | Cookie name. |
[in] | value | Cookie value. |
◆ start()
void QtlSimpleWebRequest::start |
( |
| ) |
|
Start the Web request.
The completion will be notified later using the completed() signal. Can be called only once. Subsequent calls are ignored.
◆ isStarted()
bool QtlSimpleWebRequest::isStarted |
( |
| ) |
const |
|
inline |
Check if the request was already started.
- Returns
- True if the request was already started, false otherwise.
◆ isCompleted()
bool QtlSimpleWebRequest::isCompleted |
( |
| ) |
const |
|
inline |
Check if the request is completed.
- Returns
- True if the request is completed, false otherwise.
◆ completed
void QtlSimpleWebRequest::completed |
( |
bool |
success, |
|
|
const QUrl & |
url, |
|
|
const QString & |
response, |
|
|
const QString & |
mimeType |
|
) |
| |
|
signal |
Emitted when the request is completed.
- Parameters
-
[in] | success | True on success, false on error (network error for instance). |
[in] | url | URL of the returned content. May not be the same as the original URL is some redirection occured. |
[in] | response | If success is true, contains the text of the response. If status is false, contains an error message. |
[in] | mimeType | If success is true, contains the MIME type of the response. Examples: "text/html", "text/plain", "application/json". |
◆ httpReadyRead
void QtlSimpleWebRequest::httpReadyRead |
( |
| ) |
|
|
privateslot |
Invoked when data is available from HTTP.
◆ httpFinished
void QtlSimpleWebRequest::httpFinished |
( |
| ) |
|
|
privateslot |
Invoked when HTTP request completes.
◆ startRequest()
void QtlSimpleWebRequest::startRequest |
( |
const QUrl & |
url | ) |
|
|
private |
Start an HTTP request.
Used in original request and all redirections.
- Parameters
-
◆ emitCompleted()
void QtlSimpleWebRequest::emitCompleted |
( |
const QString & |
error | ) |
|
|
private |
Emit the completed() signal and delete this instance.
- Parameters
-
[in] | error | Error message, empty on success. |
◆ _nullLog
◆ _log
◆ _started
bool QtlSimpleWebRequest::_started |
|
private |
◆ _completed
bool QtlSimpleWebRequest::_completed |
|
private |
◆ _url
QUrl QtlSimpleWebRequest::_url |
|
private |
◆ _cookies
QList<QNetworkCookie> QtlSimpleWebRequest::_cookies |
|
private |
◆ _maxResponseSize
const int QtlSimpleWebRequest::_maxResponseSize |
|
private |
Maximum size in bytes of response.
◆ _netwManager
QNetworkAccessManager QtlSimpleWebRequest::_netwManager |
|
private |
Network manager for all requests.
◆ _reply
QNetworkReply* QtlSimpleWebRequest::_reply |
|
private |
◆ _text
QString QtlSimpleWebRequest::_text |
|
private |
◆ _contentType
QString QtlSimpleWebRequest::_contentType |
|
private |
◆ _redirected
int QtlSimpleWebRequest::_redirected |
|
private |
The documentation for this class was generated from the following files: