forked from ondra/server-sdk
64 lines
1.5 KiB
C++
64 lines
1.5 KiB
C++
#include "soaprequest.h"
|
|
|
|
#include <utility>
|
|
|
|
namespace serversdk {
|
|
|
|
SoapRequest::SoapRequest(QString action, const QString& endpoint, const QByteArray& data)
|
|
: mSoapAction(std::move(action))
|
|
{
|
|
setType("POST");
|
|
setUrl(endpoint);
|
|
setRequestData(data);
|
|
}
|
|
|
|
QNetworkRequest SoapRequest::networkRequest() const
|
|
{
|
|
Q_ASSERT(!this->url().isEmpty());
|
|
QNetworkRequest request = Request::networkRequest();
|
|
|
|
// Have to set header
|
|
QString header;
|
|
|
|
if (isSoapVersion12()) {
|
|
// qCDebug(soap) << "SOAP version: 1.2";
|
|
header = QString("application/soap+xml;charset=UTF-8;action=%2").arg(soapAction());
|
|
request.setRawHeader("Content-Type", header.toUtf8());
|
|
} else {
|
|
// qCDebug(soap) << "SOAP version: 1.1";
|
|
request.setRawHeader("Content-Type", "text/xml");
|
|
request.setRawHeader("SoapAction", soapAction().toUtf8());
|
|
}
|
|
|
|
if ( !userName().isEmpty() && !password().isEmpty() )
|
|
request.setRawHeader("Authorization", this->basicAuthorization().toUtf8());
|
|
// Enabled compression
|
|
request.setRawHeader("Accept-Encoding", "gzip, deflate");
|
|
|
|
return request;
|
|
}
|
|
|
|
QString SoapRequest::soapAction() const
|
|
{
|
|
return mSoapAction;
|
|
}
|
|
|
|
void SoapRequest::setSoapAction(const QString &soapAction)
|
|
{
|
|
mSoapAction = soapAction;
|
|
}
|
|
|
|
bool SoapRequest::isSoapVersion12() const
|
|
{
|
|
return mSoapVersion12;
|
|
}
|
|
|
|
void SoapRequest::setSoapVersion12(bool soapVersion12)
|
|
{
|
|
mSoapVersion12 = soapVersion12;
|
|
}
|
|
|
|
|
|
|
|
} // namespace serversdk
|